Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5882ca6

Browse files
committed
Call xlc __isync() after, not before, associated compare-and-swap.
Architecture reference material specifies this order, and s_lock.hinline assembly agrees. The former order failed to provide mutualexclusion to lwlock.c and perhaps to other clients. The two xlcbuildfarm members, hornet and mandrill, have failed sixteen times withduplicate key errors involving pg_class_oid_index or pg_type_oid_index.Back-patch to 9.5, where commitb64d92fintroduced atomics.Reviewed by Andres Freund and Tom Lane.
1 parent481725c commit5882ca6

File tree

5 files changed

+47
-8
lines changed

5 files changed

+47
-8
lines changed

‎src/bin/pgbench/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/exprparse.c
22
/exprscan.c
33
/pgbench
4+
/tmp_check/

‎src/bin/pgbench/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ clean distclean:
4040

4141
maintainer-clean: distclean
4242
rm -f exprparse.c exprscan.c
43+
44+
check:
45+
$(prove_check)
46+
47+
installcheck:
48+
$(prove_installcheck)

‎src/bin/pgbench/t/001_pgbench.pl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use strict;
2+
use warnings;
3+
4+
use PostgresNode;
5+
use TestLib;
6+
use Test::Moretests=> 3;
7+
8+
# Test concurrent insertion into table with UNIQUE oid column. DDL expects
9+
# GetNewOidWithIndex() to successfully avoid violating uniqueness for indexes
10+
# like pg_class_oid_index and pg_proc_oid_index. This indirectly exercises
11+
# LWLock and spinlock concurrency. This test makes a 5-MiB table.
12+
my$node = get_new_node('main');
13+
$node->init;
14+
$node->start;
15+
$node->psql('postgres',
16+
'CREATE UNLOGGED TABLE oid_tbl () WITH OIDS;'
17+
.'ALTER TABLE oid_tbl ADD UNIQUE (oid);');
18+
my$script =$node->basedir .'/pgbench_script';
19+
append_to_file($script,
20+
'INSERT INTO oid_tbl SELECT FROM generate_series(1,1000);');
21+
$node->command_like(
22+
[qw(pgbench --no-vacuum --client=5 --protocol=prepared
23+
--transactions=25 --file),$script ],
24+
qr{processed: 125/125},
25+
'concurrent OID generation');

‎src/include/port/atomics/generic-xlc.h

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,23 @@ static inline bool
4040
pg_atomic_compare_exchange_u32_impl(volatilepg_atomic_uint32*ptr,
4141
uint32*expected,uint32newval)
4242
{
43+
/*
44+
* XXX: __compare_and_swap is defined to take signed parameters, but that
45+
* shouldn't matter since we don't perform any arithmetic operations.
46+
*/
47+
boolret=__compare_and_swap((volatileint*)&ptr->value,
48+
(int*)expected, (int)newval);
49+
4350
/*
4451
* xlc's documentation tells us:
4552
* "If __compare_and_swap is used as a locking primitive, insert a call to
4653
* the __isync built-in function at the start of any critical sections."
54+
*
55+
* The critical section begins immediately after __compare_and_swap().
4756
*/
4857
__isync();
4958

50-
/*
51-
* XXX: __compare_and_swap is defined to take signed parameters, but that
52-
* shouldn't matter since we don't perform any arithmetic operations.
53-
*/
54-
return__compare_and_swap((volatileint*)&ptr->value,
55-
(int*)expected, (int)newval);
59+
returnret;
5660
}
5761

5862
#definePG_HAVE_ATOMIC_FETCH_ADD_U32
@@ -69,10 +73,12 @@ static inline bool
6973
pg_atomic_compare_exchange_u64_impl(volatilepg_atomic_uint64*ptr,
7074
uint64*expected,uint64newval)
7175
{
76+
boolret=__compare_and_swaplp((volatilelong*)&ptr->value,
77+
(long*)expected, (long)newval);
78+
7279
__isync();
7380

74-
return__compare_and_swaplp((volatilelong*)&ptr->value,
75-
(long*)expected, (long)newval);;
81+
returnret;
7682
}
7783

7884
#definePG_HAVE_ATOMIC_FETCH_ADD_U64

‎src/tools/msvc/clean.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ if exist src\bin\pg_basebackup\tmp_check rd /s /q src\bin\pg_basebackup\tmp_chec
9494
ifexist src\bin\pg_config\tmp_checkrd /s /q src\bin\pg_config\tmp_check
9595
ifexist src\bin\pg_ctl\tmp_checkrd /s /q src\bin\pg_ctl\tmp_check
9696
ifexist src\bin\pg_rewind\tmp_checkrd /s /q src\bin\pg_rewind\tmp_check
97+
ifexist src\bin\pgbench\tmp_checkrd /s /q src\bin\pgbench\tmp_check
9798
ifexist src\bin\scripts\tmp_checkrd /s /q src\bin\scripts\tmp_check
9899

99100
REM Clean up datafiles built with contrib

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp