mirror of
https://github.com/postgres/postgres.git
synced 2025-05-09 18:21:05 +03:00
isolationtester: append session name to application_name.
When writing / debugging an isolation test it sometimes is useful to see which session holds what lock etc. To make it easier, both as part of spec files and interactively, append the session name to application_name. Since b1907d688 application_name already contains the test name, this appends the session's name to that. insert-conflict-specconflict did something like this manually, which can now be removed. As we have done lately with other test infrastructure improvements, backpatch this change, to make it easier to backpatch tests. Author: Andres Freund <andres@anarazel.de> Reviewed-By: Michael Paquier <michael@paquier.xyz> Reviewed-By: Andrew Dunstan <andrew@dunslane.net> Discussion: https://postgr.es/m/20211211012052.2blmzcmxnxqawd2z@alap3.anarazel.de Backpatch: 10-, to make backpatching of tests easier.
This commit is contained in:
parent
7615edd1db
commit
5b5455b035
@ -490,15 +490,15 @@ step controller_print_speculative_locks:
|
|||||||
WHERE
|
WHERE
|
||||||
locktype IN ('spectoken', 'transactionid')
|
locktype IN ('spectoken', 'transactionid')
|
||||||
AND pa.datname = current_database()
|
AND pa.datname = current_database()
|
||||||
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict-s%'
|
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict/s%'
|
||||||
ORDER BY 1, 2, 3, 4;
|
ORDER BY 1, 2, 3, 4;
|
||||||
|
|
||||||
application_name |locktype |mode |granted
|
application_name |locktype |mode |granted
|
||||||
-----------------------------------------+-------------+-------------+-------
|
-----------------------------------------+-------------+-------------+-------
|
||||||
isolation/insert-conflict-specconflict-s1|spectoken |ShareLock |f
|
isolation/insert-conflict-specconflict/s1|spectoken |ShareLock |f
|
||||||
isolation/insert-conflict-specconflict-s1|transactionid|ExclusiveLock|t
|
isolation/insert-conflict-specconflict/s1|transactionid|ExclusiveLock|t
|
||||||
isolation/insert-conflict-specconflict-s2|spectoken |ExclusiveLock|t
|
isolation/insert-conflict-specconflict/s2|spectoken |ExclusiveLock|t
|
||||||
isolation/insert-conflict-specconflict-s2|transactionid|ExclusiveLock|t
|
isolation/insert-conflict-specconflict/s2|transactionid|ExclusiveLock|t
|
||||||
(4 rows)
|
(4 rows)
|
||||||
|
|
||||||
step controller_unlock_2_4: SELECT pg_advisory_unlock(2, 4);
|
step controller_unlock_2_4: SELECT pg_advisory_unlock(2, 4);
|
||||||
@ -517,14 +517,14 @@ step controller_print_speculative_locks:
|
|||||||
WHERE
|
WHERE
|
||||||
locktype IN ('spectoken', 'transactionid')
|
locktype IN ('spectoken', 'transactionid')
|
||||||
AND pa.datname = current_database()
|
AND pa.datname = current_database()
|
||||||
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict-s%'
|
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict/s%'
|
||||||
ORDER BY 1, 2, 3, 4;
|
ORDER BY 1, 2, 3, 4;
|
||||||
|
|
||||||
application_name |locktype |mode |granted
|
application_name |locktype |mode |granted
|
||||||
-----------------------------------------+-------------+-------------+-------
|
-----------------------------------------+-------------+-------------+-------
|
||||||
isolation/insert-conflict-specconflict-s1|transactionid|ExclusiveLock|t
|
isolation/insert-conflict-specconflict/s1|transactionid|ExclusiveLock|t
|
||||||
isolation/insert-conflict-specconflict-s1|transactionid|ShareLock |f
|
isolation/insert-conflict-specconflict/s1|transactionid|ShareLock |f
|
||||||
isolation/insert-conflict-specconflict-s2|transactionid|ExclusiveLock|t
|
isolation/insert-conflict-specconflict/s2|transactionid|ExclusiveLock|t
|
||||||
(3 rows)
|
(3 rows)
|
||||||
|
|
||||||
step s2_commit: COMMIT;
|
step s2_commit: COMMIT;
|
||||||
@ -544,7 +544,7 @@ step controller_print_speculative_locks:
|
|||||||
WHERE
|
WHERE
|
||||||
locktype IN ('spectoken', 'transactionid')
|
locktype IN ('spectoken', 'transactionid')
|
||||||
AND pa.datname = current_database()
|
AND pa.datname = current_database()
|
||||||
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict-s%'
|
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict/s%'
|
||||||
ORDER BY 1, 2, 3, 4;
|
ORDER BY 1, 2, 3, 4;
|
||||||
|
|
||||||
application_name|locktype|mode|granted
|
application_name|locktype|mode|granted
|
||||||
|
@ -154,10 +154,14 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
for (i = 0; i < nconns; i++)
|
for (i = 0; i < nconns; i++)
|
||||||
{
|
{
|
||||||
|
const char *sessionname;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
conns[i].sessionname = "control connection";
|
sessionname = "control connection";
|
||||||
else
|
else
|
||||||
conns[i].sessionname = testspec->sessions[i - 1]->name;
|
sessionname = testspec->sessions[i - 1]->name;
|
||||||
|
|
||||||
|
conns[i].sessionname = sessionname;
|
||||||
|
|
||||||
conns[i].conn = PQconnectdb(conninfo);
|
conns[i].conn = PQconnectdb(conninfo);
|
||||||
if (PQstatus(conns[i].conn) != CONNECTION_OK)
|
if (PQstatus(conns[i].conn) != CONNECTION_OK)
|
||||||
@ -182,6 +186,26 @@ main(int argc, char **argv)
|
|||||||
blackholeNoticeProcessor,
|
blackholeNoticeProcessor,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Similarly, append the session name to application_name to make it
|
||||||
|
* easier to map spec file sessions to log output and
|
||||||
|
* pg_stat_activity. The reason to append instead of just setting the
|
||||||
|
* name is that we don't know the name of the test currently running.
|
||||||
|
*/
|
||||||
|
res = PQexecParams(conns[i].conn,
|
||||||
|
"SELECT set_config('application_name',\n"
|
||||||
|
" current_setting('application_name') || '/' || $1,\n"
|
||||||
|
" false)",
|
||||||
|
1, NULL,
|
||||||
|
&sessionname,
|
||||||
|
NULL, NULL, 0);
|
||||||
|
if (PQresultStatus(res) != PGRES_TUPLES_OK)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "setting of application name failed: %s",
|
||||||
|
PQerrorMessage(conns[i].conn));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Save each connection's backend PID for subsequent use. */
|
/* Save each connection's backend PID for subsequent use. */
|
||||||
conns[i].backend_pid = PQbackendPID(conns[i].conn);
|
conns[i].backend_pid = PQbackendPID(conns[i].conn);
|
||||||
conns[i].backend_pid_str = psprintf("%d", conns[i].backend_pid);
|
conns[i].backend_pid_str = psprintf("%d", conns[i].backend_pid);
|
||||||
|
@ -47,7 +47,6 @@ session controller
|
|||||||
setup
|
setup
|
||||||
{
|
{
|
||||||
SET default_transaction_isolation = 'read committed';
|
SET default_transaction_isolation = 'read committed';
|
||||||
SET application_name = 'isolation/insert-conflict-specconflict-controller';
|
|
||||||
}
|
}
|
||||||
step controller_locks {SELECT pg_advisory_lock(sess, lock), sess, lock FROM generate_series(1, 2) a(sess), generate_series(1,3) b(lock);}
|
step controller_locks {SELECT pg_advisory_lock(sess, lock), sess, lock FROM generate_series(1, 2) a(sess), generate_series(1,3) b(lock);}
|
||||||
step controller_unlock_1_1 { SELECT pg_advisory_unlock(1, 1); }
|
step controller_unlock_1_1 { SELECT pg_advisory_unlock(1, 1); }
|
||||||
@ -66,7 +65,7 @@ step controller_print_speculative_locks {
|
|||||||
WHERE
|
WHERE
|
||||||
locktype IN ('spectoken', 'transactionid')
|
locktype IN ('spectoken', 'transactionid')
|
||||||
AND pa.datname = current_database()
|
AND pa.datname = current_database()
|
||||||
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict-s%'
|
AND pa.application_name LIKE 'isolation/insert-conflict-specconflict/s%'
|
||||||
ORDER BY 1, 2, 3, 4;
|
ORDER BY 1, 2, 3, 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +74,6 @@ setup
|
|||||||
{
|
{
|
||||||
SET default_transaction_isolation = 'read committed';
|
SET default_transaction_isolation = 'read committed';
|
||||||
SET spec.session = 1;
|
SET spec.session = 1;
|
||||||
SET application_name = 'isolation/insert-conflict-specconflict-s1';
|
|
||||||
}
|
}
|
||||||
step s1_begin { BEGIN; }
|
step s1_begin { BEGIN; }
|
||||||
step s1_create_non_unique_index { CREATE INDEX upserttest_key_idx ON upserttest((blurt_and_lock_4(key))); }
|
step s1_create_non_unique_index { CREATE INDEX upserttest_key_idx ON upserttest((blurt_and_lock_4(key))); }
|
||||||
@ -90,7 +88,6 @@ setup
|
|||||||
{
|
{
|
||||||
SET default_transaction_isolation = 'read committed';
|
SET default_transaction_isolation = 'read committed';
|
||||||
SET spec.session = 2;
|
SET spec.session = 2;
|
||||||
SET application_name = 'isolation/insert-conflict-specconflict-s2';
|
|
||||||
}
|
}
|
||||||
step s2_begin { BEGIN; }
|
step s2_begin { BEGIN; }
|
||||||
step s2_upsert { INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; }
|
step s2_upsert { INSERT INTO upserttest(key, data) VALUES('k1', 'inserted s2') ON CONFLICT (blurt_and_lock_123(key)) DO UPDATE SET data = upserttest.data || ' with conflict update s2'; }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user