Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Hackers > B-tree "finish ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 9509 of 10965
Post > Topic >>

B-tree "finish incomplete split" bug

by heikki@[EMAIL PROTECTED] ("Heikki Linnakangas") Jun 11, 2008 at 11:25 AM

This is a multi-part message in MIME format.

--------------010304030507000509070703
Content-Type: text/plain;
	format=flowed;
	charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit

While testing my xlogutils.c refactoring patch, I bumped into an 
existing bug in the B-tree code that finishes an incomplete split:

btree_xlog_cleanup() calls _bt_insert_parent() to insert the parent 
pointer. If the split page was the root page, _bt_insert_parent() 
creates a new root page by calling _bt_newroot(). _bt_newroot() calls 
CacheInvalidateRelcache() to notify other backends, but 
CacheInvalidateRelcache causes a segfault when called during WAL replay, 
because the invalidation infrastructure hasn't been initialized yet.

This bug was introduced in 8.2, when we started to cache metapage 
information in relcache. It's no wonder that no-one has bumped into this 
in the field, as the window for that to happen is extremely small; I had 
to inject an "XLogFlush(); elog(PANIC)" into _bt_split to trigger it. I 
wish we had regression tests for WAL recovery :-(.

The trivial fix is to not call CacheInvalidateRelcache() in recovery 
(patch attached). Another option is to put the check into 
CacheInvalidateRelcache() itself, but in the name of consistency we 
should then put the same check into the other CacheInvalidate* variants 
as well. As nbtinsert.c is the only place that calls 
CacheInvalidateRelcache during WAL replay, I'm going to do the trivial
fix.

-- 
   Heikki Lin****angas
   EnterpriseDB   http://www.enterprisedb.com

--------------010304030507000509070703
Content-Type: text/x-diff;
	name="fix-finish-split-1.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
	filename="fix-finish-split-1.patch"

Index: src/backend/access/nbtree/nbtinsert.c
===================================================================
RCS file:
/home/hlin****a/pgcvsrepository/pgsql/src/backend/access/nbtree/nbtinsert.c,v
retrieving revision 1.146.2.2
diff -c -r1.146.2.2 nbtinsert.c
*** src/backend/access/nbtree/nbtinsert.c	31 Dec 2007 04:52:20
-0000	1.146.2.2
--- src/backend/access/nbtree/nbtinsert.c	11 Jun 2008 08:20:25 -0000
***************
*** 690,696 ****
  		/* release buffers; send out relcache inval if metapage changed */
  		if (BufferIsValid(metabuf))
  		{
! 			CacheInvalidateRelcache(rel);
  			_bt_relbuf(rel, metabuf);
  		}
  
--- 690,697 ----
  		/* release buffers; send out relcache inval if metapage changed */
  		if (BufferIsValid(metabuf))
  		{
! 			if (!InRecovery)
! 				CacheInvalidateRelcache(rel);
  			_bt_relbuf(rel, metabuf);
  		}
  
***************
*** 1623,1629 ****
  	END_CRIT_SECTION();
  
  	/* send out relcache inval for metapage change */
! 	CacheInvalidateRelcache(rel);
  
  	/* done with metapage */
  	_bt_relbuf(rel, metabuf);
--- 1627,1634 ----
  	END_CRIT_SECTION();
  
  	/* send out relcache inval for metapage change */
! 	if (!InRecovery)
! 		CacheInvalidateRelcache(rel);
  
  	/* done with metapage */
  	_bt_relbuf(rel, metabuf);

--------------010304030507000509070703
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

--------------010304030507000509070703--
 




 2 Posts in Topic:
B-tree "finish incomplete split" bug
heikki@[EMAIL PROTECTED]   2008-06-11 11:25:37 
Re: B-tree "finish incomplete split" bug
tgl@[EMAIL PROTECTED] (T  2008-06-11 10:15:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 9:29:52 CST 2008.