@@ -218,11 +218,11 @@ func TestWriteLoadStatsAccounting(t *testing.T) {
218
218
ReplicationMode : base .ReplicationManual ,
219
219
}
220
220
args .ServerArgs .Knobs .Store = & StoreTestingKnobs {DisableCanAckBeforeApplication : true }
221
- tc := serverutils .StartCluster (t , 1 , args )
221
+ tc := serverutils .StartCluster (t , 3 , args )
222
+ defer tc .Stopper ().Stop (ctx )
222
223
223
224
const epsilonAllowed = 5
224
225
225
- defer tc .Stopper ().Stop (ctx )
226
226
ts := tc .Server (0 )
227
227
db := ts .DB ()
228
228
conn := tc .ServerConn (0 )
@@ -246,52 +246,82 @@ func TestWriteLoadStatsAccounting(t *testing.T) {
246
246
{1234 , 1234 , 1234 , 0 , 1234 * writeSize , 0 },
247
247
}
248
248
249
- store , err := ts .GetStores ().(* Stores ).GetStore (ts .GetFirstStoreID ())
249
+ tc .AddVotersOrFatal (t , scratchKey , tc .Target (1 ), tc .Target (2 ))
250
+ s1 , err := tc .Server (0 ).GetStores ().(* Stores ).GetStore (tc .Server (0 ).GetFirstStoreID ())
250
251
require .NoError (t , err )
251
-
252
- repl := store .LookupReplica (roachpb .RKey (scratchKey ))
253
- require .NotNil (t , repl )
252
+ lhRepl := s1 .LookupReplica (roachpb .RKey (scratchKey ))
253
+ require .NotNil (t , lhRepl )
254
+ s2 , err := tc .Server (1 ).GetStores ().(* Stores ).GetStore (tc .Server (1 ).GetFirstStoreID ())
255
+ require .NoError (t , err )
256
+ followerRepl1 := s2 .LookupReplica (roachpb .RKey (scratchKey ))
257
+ require .NotNil (t , followerRepl1 )
258
+ s3 , err := tc .Server (2 ).GetStores ().(* Stores ).GetStore (tc .Server (2 ).GetFirstStoreID ())
259
+ require .NoError (t , err )
260
+ followerRepl2 := s3 .LookupReplica (roachpb .RKey (scratchKey ))
261
+ require .NotNil (t , followerRepl2 )
254
262
255
263
// Disable the consistency checker, to avoid interleaving requests
256
- // artificially inflating measurement due to consistency checking.
264
+ // artificially inflating measurement due to consistency checking. Also,
265
+ // disable the mvcc gc queue and raft log queue to avoid them issuing
266
+ // interleaving requests as well.
257
267
sqlDB .Exec (t , `SET CLUSTER SETTING server.consistency_check.interval = '0'` )
258
268
sqlDB .Exec (t , `SET CLUSTER SETTING kv.range_split.by_load.enabled = false` )
269
+ sqlDB .Exec (t , `SET CLUSTER SETTING kv.mvcc_gc_queue.enabled = false` )
270
+ sqlDB .Exec (t , `SET CLUSTER SETTING kv.raft_log_queue.enabled = false` )
259
271
260
272
for _ , testCase := range testCases {
261
273
// Reset the request counts to 0 before sending to clear previous requests.
262
- repl .loadStats .Reset ()
263
-
264
- requestsBefore := repl .loadStats .TestingGetSum (load .Requests )
265
- writesBefore := repl .loadStats .TestingGetSum (load .WriteKeys )
266
- readsBefore := repl .loadStats .TestingGetSum (load .ReadKeys )
267
- readBytesBefore := repl .loadStats .TestingGetSum (load .ReadBytes )
268
- writeBytesBefore := repl .loadStats .TestingGetSum (load .WriteBytes )
274
+ lhRepl .loadStats .Reset ()
275
+ followerRepl1 .loadStats .Reset ()
276
+ followerRepl2 .loadStats .Reset ()
277
+
278
+ requestsBefore := lhRepl .loadStats .TestingGetSum (load .Requests )
279
+ readsBefore := lhRepl .loadStats .TestingGetSum (load .ReadKeys )
280
+ lhWritesBefore := lhRepl .loadStats .TestingGetSum (load .WriteKeys )
281
+ readBytesBefore := lhRepl .loadStats .TestingGetSum (load .ReadBytes )
282
+ lhWriteBytesBefore := lhRepl .loadStats .TestingGetSum (load .WriteBytes )
283
+ follower1WriteBytesBefore := followerRepl1 .loadStats .TestingGetSum (load .WriteBytes )
284
+ follower2WriteBytesBefore := followerRepl2 .loadStats .TestingGetSum (load .WriteBytes )
269
285
270
286
for i := 0 ; i < testCase .writes ; i ++ {
271
287
_ , pErr := db .Inc (ctx , scratchKey , 1 )
272
288
require .Nil (t , pErr )
273
289
}
274
290
require .Equal (t , 0.0 , requestsBefore )
275
- require .Equal (t , 0.0 , writesBefore )
291
+ require .Equal (t , 0.0 , lhWritesBefore )
276
292
require .Equal (t , 0.0 , readsBefore )
277
- require .Equal (t , 0.0 , writeBytesBefore )
293
+ require .Equal (t , 0.0 , lhWriteBytesBefore )
278
294
require .Equal (t , 0.0 , readBytesBefore )
279
-
280
- requestsAfter := repl .loadStats .TestingGetSum (load .Requests )
281
- writesAfter := repl .loadStats .TestingGetSum (load .WriteKeys )
282
- readsAfter := repl .loadStats .TestingGetSum (load .ReadKeys )
283
- readBytesAfter := repl .loadStats .TestingGetSum (load .ReadBytes )
284
- writeBytesAfter := repl .loadStats .TestingGetSum (load .WriteBytes )
295
+ require .Equal (t , 0.0 , follower1WriteBytesBefore )
296
+ require .Equal (t , 0.0 , follower2WriteBytesBefore )
297
+
298
+ require .NoError (t , waitForApplication (
299
+ ctx ,
300
+ s1 .cfg .NodeDialer ,
301
+ lhRepl .GetRangeID (),
302
+ lhRepl .Desc ().Replicas ().Descriptors (),
303
+ lhRepl .GetLeaseAppliedIndex (),
304
+ ))
305
+
306
+ requestsAfter := lhRepl .loadStats .TestingGetSum (load .Requests )
307
+ lhWritesAfter := lhRepl .loadStats .TestingGetSum (load .WriteKeys )
308
+ readsAfter := lhRepl .loadStats .TestingGetSum (load .ReadKeys )
309
+ readBytesAfter := lhRepl .loadStats .TestingGetSum (load .ReadBytes )
310
+ lhWriteBytesAfter := lhRepl .loadStats .TestingGetSum (load .WriteBytes )
311
+ follower1WriteBytesAfter := followerRepl1 .loadStats .TestingGetSum (load .WriteBytes )
312
+ follower2WriteBytesAfter := followerRepl2 .loadStats .TestingGetSum (load .WriteBytes )
285
313
286
314
assertGreaterThanInDelta (t , testCase .expectedRQPS , requestsAfter , epsilonAllowed )
287
- assertGreaterThanInDelta (t , testCase .expectedWPS , writesAfter , epsilonAllowed )
315
+ assertGreaterThanInDelta (t , testCase .expectedWPS , lhWritesAfter , epsilonAllowed )
288
316
assertGreaterThanInDelta (t , testCase .expectedRPS , readsAfter , epsilonAllowed )
289
317
assertGreaterThanInDelta (t , testCase .expectedRBPS , readBytesAfter , epsilonAllowed )
290
318
// NB: We assert that the written bytes is greater than the write
291
319
// batch request size. However the size multiplication factor,
292
320
// varies between 3 and 5 so we instead assert that it is greater
293
321
// than the logical bytes.
294
- require .GreaterOrEqual (t , writeBytesAfter , testCase .expectedWBPS )
322
+ require .GreaterOrEqual (t , lhWriteBytesAfter , testCase .expectedWBPS )
323
+ require .GreaterOrEqual (t , follower1WriteBytesAfter , testCase .expectedWBPS )
324
+ require .GreaterOrEqual (t , follower2WriteBytesAfter , testCase .expectedWBPS )
295
325
}
296
326
}
297
327
0 commit comments