postgresql/src
Tom Lane ed9cc2b5df Fix bogus concurrent use of _hash_getnewbuf() in bucket split code.
_hash_splitbucket() obtained the base page of the new bucket by calling
_hash_getnewbuf(), but it held no exclusive lock that would prevent some
other process from calling _hash_getnewbuf() at the same time.  This is
contrary to _hash_getnewbuf()'s API spec and could in fact cause failures.
In practice, we must only call that function while holding write lock on
the hash index's metapage.

An additional problem was that we'd already modified the metapage's bucket
mapping data, meaning that failure to extend the index would leave us with
a corrupt index.

Fix both issues by moving the _hash_getnewbuf() call to just before we
modify the metapage in _hash_expandtable().

Unfortunately there's still a large problem here, which is that we could
also incur ENOSPC while trying to get an overflow page for the new bucket.
That would leave the index corrupt in a more subtle way, namely that some
index tuples that should be in the new bucket might still be in the old
one.  Fixing that seems substantially more difficult; even preallocating as
many pages as we could possibly need wouldn't entirely guarantee that the
bucket split would complete successfully.  So for today let's just deal
with the base case.

Per report from Antonin Houska.  Back-patch to all active branches.
2015-03-30 16:40:05 -04:00
..
backend Fix bogus concurrent use of _hash_getnewbuf() in bucket split code. 2015-03-30 16:40:05 -04:00
bin Clean up all the cruft after a pg_rewind test run. 2015-03-29 20:54:37 -04:00
common Unlink static libraries before rebuilding them. 2015-03-01 13:05:23 -05:00
include Change array_offset to return subscripts, not offsets 2015-03-30 16:13:21 -03:00
interfaces Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
makefiles Revert haphazard pgxs makefile changes 2014-12-04 08:07:59 -05:00
pl Tweak __attribute__-wrapping macros for better pgindent results. 2015-03-26 14:03:25 -04:00
port Upgrade src/port/rint.c to be POSIX-compliant. 2015-03-25 15:54:18 -04:00
template Remove duplicate specification of -Ae for HP-UX C compiler. 2015-01-13 22:52:11 -05:00
test Change array_offset to return subscripts, not offsets 2015-03-30 16:13:21 -03:00
timezone Update time zone data files to tzdata release 2015a. 2015-01-30 22:45:44 -05:00
tools Try to fix MSVC build of pg_rewind. 2015-03-23 20:26:49 +02:00
tutorial Update copyright for 2015 2015-01-06 11:43:47 -05:00
.gitignore
DEVELOPERS
Makefile Create libpgcommon, and move pg_malloc et al to it 2013-02-12 11:21:05 -03:00
Makefile.global.in Fix installcheck case for tap tests 2014-12-24 10:31:36 -05:00
Makefile.shlib Unlink static libraries before rebuilding them. 2015-03-01 13:05:23 -05:00
bcc32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
nls-global.mk Setup error context callback for transaction lock waits 2014-03-19 15:10:36 -03:00
win32.mak Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00