Skip to content

Commit 10c4ba9

Browse files
committed
Backport of NDBT_Test functionality to identify parallel steps
Originally committed in : commit 4329a1385304788d642d0dec34174a6cd7842eb7 Author: Frazer Clement <[email protected]> Date: Fri Oct 8 23:54:33 2021 +0100 Bug #32478380 DEADLOCK TIMEOUT DUE TO PROBLEM IN REDO LOG QUEUE HANDLING Originally Approved by : Maitrayi Sabaratnam <[email protected]> Change-Id: Idcd159d0da98b6ed4c8542895fcfbaa962a75240
1 parent 5b28126 commit 10c4ba9

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

storage/ndb/test/include/NDBT_Test.hpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2003, 2025, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -121,6 +121,18 @@ class NDBT_Context {
121121
* Get config by beeing friend to ndb_cluster_connection_impl - ugly
122122
*/
123123
NdbApiConfig const& getConfig() const;
124+
125+
/**
126+
* get a subrange of records - useful for splitting work amongst
127+
* threads and avoiding contention.
128+
*/
129+
static
130+
void getRecordSubRange(int records,
131+
int rangeCount,
132+
int rangeId,
133+
int& startRecord,
134+
int& stopRecord);
135+
124136
private:
125137
friend class NDBT_Step;
126138
friend class NDBT_TestSuite;
@@ -161,13 +173,17 @@ class NDBT_Step {
161173
const char* getName() { return name; }
162174
int getStepNo() { return step_no; }
163175
void setStepNo(int n) { step_no = n; }
176+
/* Parallel steps : Step x/y (x counting from 0) */
177+
int getStepTypeNo() { return step_type_no; }
178+
int getStepTypeCount() { return step_type_count; }
164179
protected:
165180
NDBT_Context* m_ctx;
166181
const char* name;
167182
NDBT_TESTFUNC* func;
168183
NDBT_TestCase* testcase;
169184
int step_no;
170-
185+
int step_type_no;
186+
int step_type_count;
171187
private:
172188
int setUp(Ndb_cluster_connection&);
173189
void tearDown();
@@ -182,7 +198,9 @@ class NDBT_ParallelStep : public NDBT_Step {
182198
public:
183199
NDBT_ParallelStep(NDBT_TestCase* ptest,
184200
const char* pname,
185-
NDBT_TESTFUNC* pfunc);
201+
NDBT_TESTFUNC* pfunc,
202+
int num = 0,
203+
int count = 1);
186204
virtual ~NDBT_ParallelStep() {}
187205
};
188206

@@ -503,7 +521,7 @@ C##suitname():NDBT_TestSuite(#suitname){ \
503521
// Add a number of equal steps to the testcase
504522
#define STEPS(stepfunc, num) \
505523
{ int i; for (i = 0; i < num; i++){ \
506-
pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc); \
524+
pts = new NDBT_ParallelStep(pt, #stepfunc, stepfunc, i, num); \
507525
pt->addStep(pts);\
508526
} }
509527

storage/ndb/test/src/NDBT_Test.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2003, 2024, Oracle and/or its affiliates.
2+
Copyright (c) 2003, 2025, Oracle and/or its affiliates.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License, version 2.0,
@@ -280,10 +280,35 @@ void NDBT_Context::setNumLoops(int _loops){
280280
loops = _loops;
281281
}
282282

283+
void NDBT_Context::getRecordSubRange(int records,
284+
int rangeCount,
285+
int rangeId,
286+
int& startRecord,
287+
int& stopRecord)
288+
{
289+
int recordsPerStep = records / rangeCount;
290+
if (recordsPerStep == 0)
291+
{
292+
recordsPerStep = 1;
293+
}
294+
startRecord = rangeId * recordsPerStep;
295+
stopRecord = startRecord + recordsPerStep;
296+
297+
if (stopRecord > records)
298+
{
299+
stopRecord = records;
300+
}
301+
if (startRecord >= records)
302+
{
303+
startRecord = stopRecord = 0;
304+
}
305+
}
306+
283307
NDBT_Step::NDBT_Step(NDBT_TestCase* ptest, const char* pname,
284308
NDBT_TESTFUNC* pfunc) :
285309
m_ctx(NULL), name(pname), func(pfunc),
286-
testcase(ptest), step_no(-1), m_ndb(NULL)
310+
testcase(ptest), step_no(-1), step_type_no(0),
311+
step_type_count(1), m_ndb(NULL)
287312
{
288313
}
289314

@@ -389,9 +414,14 @@ NDBT_Context* NDBT_Step::getContext(){
389414

390415

391416
NDBT_ParallelStep::NDBT_ParallelStep(NDBT_TestCase* ptest,
392-
const char* pname,
393-
NDBT_TESTFUNC* pfunc)
417+
const char* pname,
418+
NDBT_TESTFUNC* pfunc,
419+
int num,
420+
int count)
394421
: NDBT_Step(ptest, pname, pfunc) {
422+
require(num < count);
423+
step_type_no = num;
424+
step_type_count = count;
395425
}
396426
NDBT_Verifier::NDBT_Verifier(NDBT_TestCase* ptest,
397427
const char* pname,

0 commit comments

Comments
 (0)