Skip to content

Commit ec40d4e

Browse files
committed
Adds support for Foreign keys table in Pstress
https://perconadev.atlassian.net/browse/PSTRESS-152 Introduced support for Foreign key tables in Pstress. * The tables with foreign key references are suffixed with `_fk` while creating the tables. * These FK tables include `ifk_col` column referencing parent table's `ipkey`. * Example : When --fk-prob is 50 --tables 100 options are passed, there is a 50% chance there will be a table tt_N_fk whose parent would be tt_N. * To fully test FK behaviour, use `--fk-prob=100 --pk-prob=100` * The FK tables can be disabled with `--no-fk` option. Fixed transaction behaviour: * Ensured `START TRANSACTION` doesn't block other sessions by running transactions independently. Adjusted the default probabilities of some features: * A new option called partition-prob is added which controls the number of partition tables created and is set to 10% by default. * The exisiting option ratio-normal-temp is replaced with a new option, temporary-prob to control the number of temporary tables and is set to 10% by default. * The exisiting option commit-rollback-ratio is replaced with a new option, commit-prob, which controls the probability of executing commit and is set to 95 by default. * Decreased the probability of using SAVEPOINT in a transaction from 50% to 10%. * The option `primary-key-probability` is renamed to `--pk-prob` fpr clarity. Thanks Rahul Malik for the contribution. (github.com/Percona-QA/pull/92)
1 parent e57d733 commit ec40d4e

File tree

4 files changed

+381
-115
lines changed

4 files changed

+381
-115
lines changed

src/common.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,8 @@ struct Option {
5959
INDEX_COLUMNS,
6060
NO_AUTO_INC,
6161
NO_DESC_INDEX,
62-
NO_TEMPORARY,
63-
NO_PARTITION,
6462
ONLY_TEMPORARY,
6563
ONLY_PARTITION,
66-
TEMPORARY_TO_NORMAL_RATIO,
6764
INITIAL_RECORDS_IN_TABLE,
6865
NUMBER_OF_SECONDS_WORKLOAD,
6966
ALTER_TABLE_ENCRYPTION,
@@ -121,7 +118,7 @@ struct Option {
121118
MYSQLD_SERVER_OPTION = 'z',
122119
TRANSATION_PRB_K,
123120
TRANSACTIONS_SIZE,
124-
COMMMIT_TO_ROLLBACK_RATIO,
121+
COMMIT_PROB,
125122
SAVEPOINT_PRB_K,
126123
CHECK_TABLE,
127124
CHECK_TABLE_PRELOAD,
@@ -144,6 +141,12 @@ struct Option {
144141
DROP_CREATE,
145142
EXACT_INITIAL_RECORDS,
146143
PREPARE,
144+
NO_TEMPORARY,
145+
NO_PARTITION,
146+
NO_FK,
147+
FK_PROB,
148+
PARTITION_PROB,
149+
TEMPORARY_PROB,
147150
MAX
148151
} option;
149152
Option(Type t, Opt o, std::string n)

src/help.cpp

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,12 @@ void add_options() {
229229
opt->setArgs(no_argument);
230230
opt->setBool(false);
231231

232+
/* No FK tables */
233+
opt = newOption(Option::BOOL, Option::NO_FK, "no-fk-tables");
234+
opt->help = "do not work on foriegn tables";
235+
opt->setArgs(no_argument);
236+
opt->setBool(false);
237+
232238
/* No Partition tables */
233239
opt = newOption(Option::BOOL, Option::NO_PARTITION, "no-partition-tables");
234240
opt->help = "do not work on partition tables";
@@ -241,12 +247,21 @@ void add_options() {
241247
opt->setArgs(no_argument);
242248
opt->setBool(false);
243249

250+
opt = newOption(Option::INT, Option::FK_PROB, "fk-prob");
251+
opt->help = R"(
252+
Probability of each normal table having the FK. Currently, FKs are only linked
253+
to the primary key of the parent table. So, even with 100% probability, a table
254+
will have an FK only if its parent has a primary key.
255+
)";
256+
opt->setInt(50);
257+
258+
opt = newOption(Option::INT, Option::PARTITION_PROB, "partition-prob");
259+
opt->help = "Probability of parititon tables";
260+
opt->setInt(10);
261+
244262
/* Ratio of temporary table to normal table */
245-
opt = newOption(Option::INT, Option::TEMPORARY_TO_NORMAL_RATIO,
246-
"ratio-normal-temp");
247-
opt->help = "ratio of normal to temporary tables. for e.g. if ratio to "
248-
"normal table to temporary is 10 . --tables 40. them only 4 "
249-
"temorary table will be created per session";
263+
opt = newOption(Option::INT, Option::TEMPORARY_PROB, "temporary-prob");
264+
opt->help = "Probability of temporary tables";
250265
opt->setInt(10);
251266

252267
/* Initial Records in table */
@@ -270,7 +285,7 @@ void add_options() {
270285
opt->setInt(1000);
271286

272287
/* primary key probability */
273-
opt = newOption(Option::INT, Option::PRIMARY_KEY, "primary-key-probability");
288+
opt = newOption(Option::INT, Option::PRIMARY_KEY, "pk-prob");
274289
opt->help = "Probability of adding primary key in a table";
275290
opt->setInt(50);
276291

@@ -684,7 +699,7 @@ void add_options() {
684699
opt =
685700
newOption(Option::BOOL, Option::LOG_QUERY_DURATION, "log-query-duration");
686701
opt->help = "Log query duration in milliseconds";
687-
opt->setBool(true);
702+
opt->setBool(false);
688703
opt->setArgs(no_argument);
689704

690705
/* log failed queries */
@@ -714,28 +729,26 @@ void add_options() {
714729
opt->setArgs(no_argument);
715730

716731
/* transaction probability */
717-
opt = newOption(Option::INT, Option::TRANSATION_PRB_K, "trx-prb-k");
732+
opt = newOption(Option::INT, Option::TRANSATION_PRB_K, "trx-prob-k");
718733
opt->help = "probability(out of 1000) of combining sql as single trx";
719-
opt->setInt(10);
734+
opt->setInt(1);
720735

721736
/* tranasaction size */
722737
opt = newOption(Option::INT, Option::TRANSACTIONS_SIZE, "trx-size");
723738
opt->help = "average size of each trx";
724-
opt->setInt(100);
725-
726-
/* commit to rollback ratio */
727-
opt = newOption(Option::INT, Option::COMMMIT_TO_ROLLBACK_RATIO,
728-
"commit-rollback-ratio");
729-
opt->help = "ratio of commit to rollback. e.g.\nif 5, then 5 "
730-
"transactions will be committed and 1 will be rollback.\n"
731-
"if 0 then all transactions will be rollback";
732-
opt->setInt(5);
739+
opt->setInt(10);
740+
741+
/* probability of executing commit */
742+
opt = newOption(Option::INT, Option::COMMIT_PROB, "commit-prob");
743+
opt->help = "probability of executing commit after a transaction. Else it "
744+
"would be rollback ";
745+
opt->setInt(95);
733746

734747
/* number of savepoints in trxs */
735-
opt = newOption(Option::INT, Option::SAVEPOINT_PRB_K, "savepoint-prb-k");
736-
opt->help = "probability of using savepoint in a transaction.\n Also 25% "
748+
opt = newOption(Option::INT, Option::SAVEPOINT_PRB_K, "savepoint-prob-k");
749+
opt->help = "probability of using savepoint in a transaction.\n Also 10% "
737750
"such transaction will be rollback to some savepoint";
738-
opt->setInt(50);
751+
opt->setInt(10);
739752

740753
/* steps */
741754
opt = newOption(Option::INT, Option::STEP, "step");

0 commit comments

Comments
 (0)