github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/kv/kvserver/testing_knobs.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package kvserver 12 13 import ( 14 "time" 15 16 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/kvserverbase" 17 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/txnwait" 18 "github.com/cockroachdb/cockroach/pkg/roachpb" 19 "github.com/cockroachdb/cockroach/pkg/util/hlc" 20 ) 21 22 // StoreTestingKnobs is a part of the context used to control parts of 23 // the system. The Testing*Filter functions are called at various 24 // points in the request pipeline if they are non-nil. These can be 25 // used either for synchronization (e.g. to write to a channel when a 26 // particular point is reached) or to change the behavior by returning 27 // an error (which aborts all further processing for the command). 28 type StoreTestingKnobs struct { 29 EvalKnobs kvserverbase.BatchEvalTestingKnobs 30 IntentResolverKnobs kvserverbase.IntentResolverTestingKnobs 31 TxnWaitKnobs txnwait.TestingKnobs 32 ConsistencyTestingKnobs ConsistencyTestingKnobs 33 34 // TestingRequestFilter is called before evaluating each request on a 35 // replica. The filter is run before the request acquires latches, so 36 // blocking in the filter will not block interfering requests. If it 37 // returns an error, the command will not be evaluated. 38 TestingRequestFilter kvserverbase.ReplicaRequestFilter 39 40 // TestingLatchFilter is called before evaluating each command on a replica 41 // but after acquiring latches for the command. Blocking in the filter will 42 // block interfering requests. If it returns an error, the command will not 43 // be evaluated. 44 TestingLatchFilter kvserverbase.ReplicaRequestFilter 45 46 // TestingProposalFilter is called before proposing each command. 47 TestingProposalFilter kvserverbase.ReplicaProposalFilter 48 49 // TestingApplyFilter is called before applying the results of a 50 // command on each replica. If it returns an error, the command will 51 // not be applied. If it returns an error on some replicas but not 52 // others, the behavior is poorly defined. 53 TestingApplyFilter kvserverbase.ReplicaApplyFilter 54 55 // TestingPostApplyFilter is called after a command is applied to 56 // rocksdb but before in-memory side effects have been processed. 57 // It is only called on the replica the proposed the command. 58 TestingPostApplyFilter kvserverbase.ReplicaApplyFilter 59 60 // TestingResponseFilter is called after the replica processes a 61 // command in order for unittests to modify the batch response, 62 // error returned to the client, or to simulate network failures. 63 TestingResponseFilter kvserverbase.ReplicaResponseFilter 64 65 // TestingRangefeedFilter is called before a replica processes a rangefeed 66 // in order for unit tests to modify the request, error returned to the client 67 // or data. 68 TestingRangefeedFilter kvserverbase.ReplicaRangefeedFilter 69 70 // A hack to manipulate the clock before sending a batch request to a replica. 71 // TODO(kaneda): This hook is not encouraged to use. Get rid of it once 72 // we make TestServer take a ManualClock. 73 ClockBeforeSend func(*hlc.Clock, roachpb.BatchRequest) 74 // MaxOffset, if set, overrides the server clock's MaxOffset at server 75 // creation time. 76 // See also DisableMaxOffsetCheck. 77 MaxOffset time.Duration 78 // DisableMaxOffsetCheck disables the rejection (in Store.Send) of requests 79 // with the timestamp too much in the future. Normally, this rejection is a 80 // good sanity check, but certain tests unfortunately insert a "message from 81 // the future" into the system to advance the clock of a TestServer. We 82 // should get rid of such practices once we make TestServer take a 83 // ManualClock. 84 DisableMaxOffsetCheck bool 85 // DontPreventUseOfOldLeaseOnStart disables the initialization of 86 // replica.mu.minLeaseProposedTS on replica.Init(). This has the effect of 87 // allowing the replica to use the lease that it had in a previous life (in 88 // case the tests persisted the engine used in said previous life). 89 DontPreventUseOfOldLeaseOnStart bool 90 // DisableAutomaticLeaseRenewal enables turning off the background worker 91 // that attempts to automatically renew expiration-based leases. 92 DisableAutomaticLeaseRenewal bool 93 // LeaseRequestEvent, if set, is called when replica.requestLeaseLocked() is 94 // called to acquire a new lease. This can be used to assert that a request 95 // triggers a lease acquisition. 96 LeaseRequestEvent func(ts hlc.Timestamp) 97 // LeaseTransferBlockedOnExtensionEvent, if set, is called when 98 // replica.TransferLease() encounters an in-progress lease extension. 99 // nextLeader is the replica that we're trying to transfer the lease to. 100 LeaseTransferBlockedOnExtensionEvent func(nextLeader roachpb.ReplicaDescriptor) 101 // DisableGCQueue disables the GC queue. 102 DisableGCQueue bool 103 // DisableMergeQueue disables the merge queue. 104 DisableMergeQueue bool 105 // DisableReplicateQueue disables the raft log queue. 106 DisableRaftLogQueue bool 107 // DisableReplicaGCQueue disables the replica GC queue. 108 DisableReplicaGCQueue bool 109 // DisableReplicateQueue disables the replication queue. 110 DisableReplicateQueue bool 111 // DisableReplicaRebalancing disables rebalancing of replicas but otherwise 112 // leaves the replicate queue operational. 113 DisableReplicaRebalancing bool 114 // DisableLoadBasedSplitting turns off LBS so no splits happen because of load. 115 DisableLoadBasedSplitting bool 116 // DisableSplitQueue disables the split queue. 117 DisableSplitQueue bool 118 // DisableTimeSeriesMaintenanceQueue disables the time series maintenance 119 // queue. 120 DisableTimeSeriesMaintenanceQueue bool 121 // DisableRaftSnapshotQueue disables the raft snapshot queue. 122 DisableRaftSnapshotQueue bool 123 // DisableConsistencyQueue disables the consistency checker. 124 DisableConsistencyQueue bool 125 // DisableScanner disables the replica scanner. 126 DisableScanner bool 127 // DisablePeriodicGossips disables periodic gossiping. 128 DisablePeriodicGossips bool 129 // DisableLeaderFollowsLeaseholder disables attempts to transfer raft 130 // leadership when it diverges from the range's leaseholder. 131 DisableLeaderFollowsLeaseholder bool 132 // DisableRefreshReasonNewLeader disables refreshing pending commands when a new 133 // leader is discovered. 134 DisableRefreshReasonNewLeader bool 135 // DisableRefreshReasonNewLeaderOrConfigChange disables refreshing pending 136 // commands when a new leader is discovered or when a config change is 137 // dropped. 138 DisableRefreshReasonNewLeaderOrConfigChange bool 139 // DisableRefreshReasonTicks disables refreshing pending commands when a 140 // snapshot is applied. 141 DisableRefreshReasonSnapshotApplied bool 142 // DisableRefreshReasonTicks disables refreshing pending commands 143 // periodically. 144 DisableRefreshReasonTicks bool 145 // DisableEagerReplicaRemoval prevents the Replica from destroying itself 146 // when it encounters a ChangeReplicasTrigger which would remove it or when 147 // a ReplicaTooOldError in a RaftMessageResponse would lead to removal. 148 // This option can lead to nasty cases during shutdown where a replica will 149 // spin attempting to acquire a split or merge lock on a RHS which will 150 // always fail and is generally not safe but is useful for testing. 151 DisableEagerReplicaRemoval bool 152 // RefreshReasonTicksPeriod overrides the default period over which 153 // pending commands are refreshed. The period is specified as a multiple 154 // of Raft group ticks. 155 RefreshReasonTicksPeriod int 156 // DisableProcessRaft disables the process raft loop. 157 DisableProcessRaft bool 158 // DisableLastProcessedCheck disables checking on replica queue last processed times. 159 DisableLastProcessedCheck bool 160 // ReplicateQueueAcceptsUnsplit allows the replication queue to 161 // process ranges that need to be split, for use in tests that use 162 // the replication queue but disable the split queue. 163 ReplicateQueueAcceptsUnsplit bool 164 // SplitQueuePurgatoryChan allows a test to control the channel used to 165 // trigger split queue purgatory processing. 166 SplitQueuePurgatoryChan <-chan time.Time 167 // SkipMinSizeCheck, if set, makes the store creation process skip the check 168 // for a minimum size. 169 SkipMinSizeCheck bool 170 // DisableLeaseCapacityGossip disables the ability of a changing number of 171 // leases to trigger the store to gossip its capacity. With this enabled, 172 // only changes in the number of replicas can cause the store to gossip its 173 // capacity. 174 DisableLeaseCapacityGossip bool 175 // SystemLogsGCPeriod is used to override the period of GC of system logs. 176 SystemLogsGCPeriod time.Duration 177 // SystemLogsGCGCDone is used to notify when system logs GC is done. 178 SystemLogsGCGCDone chan<- struct{} 179 // DontPushOnWriteIntentError will propagate a write intent error immediately 180 // instead of utilizing the intent resolver to try to push the corresponding 181 // transaction. 182 DontPushOnWriteIntentError bool 183 // DontRetryPushTxnFailures will propagate a push txn failure immediately 184 // instead of utilizing the txn wait queue to wait for the transaction to 185 // finish or be pushed by a higher priority contender. 186 DontRetryPushTxnFailures bool 187 // DontRecoverIndeterminateCommits will propagate indeterminate commit 188 // errors from failed txn pushes immediately instead of utilizing the txn 189 // recovery manager to recovery from the indeterminate state. 190 DontRecoverIndeterminateCommits bool 191 // TraceAllRaftEvents enables raft event tracing even when the current 192 // vmodule would not have enabled it. 193 TraceAllRaftEvents bool 194 // EnableUnconditionalRefreshesInRaftReady will always set the refresh reason 195 // in handleRaftReady to refreshReasonNewLeaderOrConfigChange. 196 EnableUnconditionalRefreshesInRaftReady bool 197 198 // ReceiveSnapshot is run after receiving a snapshot header but before 199 // acquiring snapshot quota or doing shouldAcceptSnapshotData checks. If an 200 // error is returned from the hook, it's sent as an ERROR SnapshotResponse. 201 ReceiveSnapshot func(*SnapshotRequest_Header) error 202 // ReplicaAddSkipRollback causes replica addition to skip the learner rollback 203 // that happens when promotion to a voter fails. 204 ReplicaAddSkipLearnerRollback func() bool 205 // ReplicaAddStopAfterLearnerSnapshot causes replica addition to return early 206 // if the func returns true. Specifically, after the learner txn is successful 207 // and after the LEARNER type snapshot, but before promoting it to a voter. 208 // This ensures the `*Replica` will be materialized on the Store when it 209 // returns. 210 ReplicaAddStopAfterLearnerSnapshot func([]roachpb.ReplicationTarget) bool 211 // ReplicaSkipLearnerSnapshot causes snapshots to never be sent to learners 212 // if the func returns true. Adding replicas proceeds as usual, though if 213 // the added replica has no prior state which can be caught up from the raft 214 // log, the result will be an voter that is unable to participate in quorum. 215 ReplicaSkipLearnerSnapshot func() bool 216 // ReplicaAddStopAfterJointConfig causes replica addition to return early if 217 // the func returns true. This happens before transitioning out of a joint 218 // configuration, after the joint configuration has been entered by means 219 // of a first ChangeReplicas transaction. If the replication change does 220 // not use joint consensus, this early return is identical to the regular 221 // return path. 222 ReplicaAddStopAfterJointConfig func() bool 223 // ReplicationAlwaysUseJointConfig causes replica addition to always go 224 // through a joint configuration, even when this isn't necessary (because 225 // the replication change affects only one replica). 226 ReplicationAlwaysUseJointConfig func() bool 227 // BeforeSnapshotSSTIngestion is run just before the SSTs are ingested when 228 // applying a snapshot. 229 BeforeSnapshotSSTIngestion func(IncomingSnapshot, SnapshotRequest_Type, []string) error 230 // BeforeRelocateOne intercepts the return values of s.relocateOne before 231 // they're being put into effect. 232 BeforeRelocateOne func(_ []roachpb.ReplicationChange, leaseTarget *roachpb.ReplicationTarget, _ error) 233 // MaxApplicationBatchSize enforces a maximum size on application batches. 234 // This can be useful for testing conditions which require commands to be 235 // applied in separate batches. 236 MaxApplicationBatchSize int 237 // RangeFeedPushTxnsInterval overrides the default value for 238 // rangefeed.Config.PushTxnsInterval. 239 RangeFeedPushTxnsInterval time.Duration 240 // RangeFeedPushTxnsAge overrides the default value for 241 // rangefeed.Config.PushTxnsAge. 242 RangeFeedPushTxnsAge time.Duration 243 } 244 245 // ModuleTestingKnobs is part of the base.ModuleTestingKnobs interface. 246 func (*StoreTestingKnobs) ModuleTestingKnobs() {}