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

Commit377a1af

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 parentc479024 commit377a1af

File tree

5 files changed

+46
-8
lines changed

5 files changed

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

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,23 @@ static inline bool
4646
pg_atomic_compare_exchange_u32_impl(volatilepg_atomic_uint32*ptr,
4747
uint32*expected,uint32newval)
4848
{
49+
/*
50+
* XXX: __compare_and_swap is defined to take signed parameters, but that
51+
* shouldn't matter since we don't perform any arithmetic operations.
52+
*/
53+
boolret=__compare_and_swap((volatileint*)&ptr->value,
54+
(int*)expected, (int)newval);
55+
4956
/*
5057
* xlc's documentation tells us:
5158
* "If __compare_and_swap is used as a locking primitive, insert a call to
5259
* the __isync built-in function at the start of any critical sections."
60+
*
61+
* The critical section begins immediately after __compare_and_swap().
5362
*/
5463
__isync();
5564

56-
/*
57-
* XXX: __compare_and_swap is defined to take signed parameters, but that
58-
* shouldn't matter since we don't perform any arithmetic operations.
59-
*/
60-
return__compare_and_swap((volatileint*)&ptr->value,
61-
(int*)expected, (int)newval);
65+
returnret;
6266
}
6367

6468
#definePG_HAVE_ATOMIC_FETCH_ADD_U32
@@ -75,10 +79,12 @@ static inline bool
7579
pg_atomic_compare_exchange_u64_impl(volatilepg_atomic_uint64*ptr,
7680
uint64*expected,uint64newval)
7781
{
82+
boolret=__compare_and_swaplp((volatilelong*)&ptr->value,
83+
(long*)expected, (long)newval);
84+
7885
__isync();
7986

80-
return__compare_and_swaplp((volatilelong*)&ptr->value,
81-
(long*)expected, (long)newval);;
87+
returnret;
8288
}
8389

8490
#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