Fix relcache reload mechanism to be more robust in the face of errors occurring during a reload, such as query-cancel.  Instead of zeroing out an existing relcache entry and rebuilding it in place, build a new relcache entry, then swap its contents with the old one, then free the new entry. This avoids problems with code believing that a previously obtained pointer to a cache entry must still reference a valid entry, as seen in recent failures on buildfarm member jaguar.  (jaguar is using CLOBBER_CACHE_ALWAYS which raises the probability of failure substantially, but the problem could occur in the field without that.)  The previous design was okay when it was made, but subtransactions and the ResourceOwner mechanism make it unsafe now.
Fix relcache reload mechanism to be more robust in the face of errors
occurring during a reload, such as query-cancel.  Instead of zeroing out
an existing relcache entry and rebuilding it in place, build a new relcache
entry, then swap its contents with the old one, then free the new entry.
This avoids problems with code believing that a previously obtained pointer
to a cache entry must still reference a valid entry, as seen in recent
failures on buildfarm member jaguar.  (jaguar is using CLOBBER_CACHE_ALWAYS
which raises the probability of failure substantially, but the problem
could occur in the field without that.)  The previous design was okay
when it was made, but subtransactions and the ResourceOwner mechanism
make it unsafe now.

Also, make more use of the already existing rd_isvalid flag, so that we
remember that the entry requires rebuilding even if the first attempt fails.

Back-patch as far as 8.2.  Prior versions have enough issues around relcache
reload anyway (due to inadequate locking) that fixing this one doesn't seem
worthwhile.

0x0FFF/gpdb,zaksoup/gpdb,Chibin/gpdb,CraigHarris/gpdb,edespino/gpdb,cjcjameson/gpdb,ashwinstar/gpdb,50wu/gpdb,rvs/gpdb,greenplum-db/gpdb,xinzweb/gpdb,Chibin/gpdb,chrishajas/gpdb,ashwinstar/gpdb,adam8157/gpdb,greenplum-db/gpdb,0x0FFF/gpdb,kaknikhil/gpdb,50wu/gpdb,royc1/gpdb,xinzweb/gpdb,CraigHarris/gpdb,CraigHarris/gpdb,lisakowen/gpdb,ahachete/gpdb,edespino/gpdb,adam8157/gpdb,Quikling/gpdb,CraigHarris/gpdb,rvs/gpdb,ahachete/gpdb,CraigHarris/gpdb,chrishajas/gpdb,janebeckman/gpdb,xuegang/gpdb,rvs/gpdb,lisakowen/gpdb,chrishajas/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,edespino/gpdb,ashwinstar/gpdb,Chibin/gpdb,yuanzhao/gpdb,cjcjameson/gpdb,greenplum-db/gpdb,xinzweb/gpdb,ahachete/gpdb,0x0FFF/gpdb,0x0FFF/gpdb,rvs/gpdb,greenplum-db/gpdb,edespino/gpdb,greenplum-db/gpdb,chrishajas/gpdb,xinzweb/gpdb,xinzweb/gpdb,yuanzhao/gpdb,Quikling/gpdb,cjcjameson/gpdb,lintzc/gpdb,xuegang/gpdb,zaksoup/gpdb,adam8157/gpdb,janebeckman/gpdb,janebeckman/gpdb,rvs/gpdb,lintzc/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,cjcjameson/gpdb,0x0FFF/gpdb,Quikling/gpdb,jmcatamney/gpdb,lintzc/gpdb,xuegang/gpdb,edespino/gpdb,50wu/gpdb,janebeckman/gpdb,ashwinstar/gpdb,Chibin/gpdb,ahachete/gpdb,CraigHarris/gpdb,chrishajas/gpdb,ahachete/gpdb,lintzc/gpdb,CraigHarris/gpdb,cjcjameson/gpdb,Quikling/gpdb,0x0FFF/gpdb,edespino/gpdb,rvs/gpdb,jmcatamney/gpdb,50wu/gpdb,zaksoup/gpdb,Chibin/gpdb,lisakowen/gpdb,50wu/gpdb,xuegang/gpdb,janebeckman/gpdb,chrishajas/gpdb,cjcjameson/gpdb,lintzc/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,kaknikhil/gpdb,lisakowen/gpdb,xinzweb/gpdb,lintzc/gpdb,janebeckman/gpdb,ashwinstar/gpdb,yuanzhao/gpdb,chrishajas/gpdb,adam8157/gpdb,adam8157/gpdb,edespino/gpdb,xuegang/gpdb,edespino/gpdb,rvs/gpdb,cjcjameson/gpdb,royc1/gpdb,adam8157/gpdb,kaknikhil/gpdb,cjcjameson/gpdb,xuegang/gpdb,Chibin/gpdb,royc1/gpdb,adam8157/gpdb,lintzc/gpdb,50wu/gpdb,edespino/gpdb,lintzc/gpdb,zaksoup/gpdb,yuanzhao/gpdb,Chibin/gpdb,xinzweb/gpdb,rvs/gpdb,yuanzhao/gpdb,janebeckman/gpdb,lisakowen/gpdb,jmcatamney/gpdb,lisakowen/gpdb,jmcatamney/gpdb,CraigHarris/gpdb,greenplum-db/gpdb,chrishajas/gpdb,Quikling/gpdb,kaknikhil/gpdb,zaksoup/gpdb,ashwinstar/gpdb,Quikling/gpdb,0x0FFF/gpdb,royc1/gpdb,xinzweb/gpdb,Chibin/gpdb,ahachete/gpdb,xuegang/gpdb,janebeckman/gpdb,xuegang/gpdb,Chibin/gpdb,rvs/gpdb,jmcatamney/gpdb,kaknikhil/gpdb,royc1/gpdb,cjcjameson/gpdb,yuanzhao/gpdb,edespino/gpdb,CraigHarris/gpdb,royc1/gpdb,cjcjameson/gpdb,zaksoup/gpdb,ashwinstar/gpdb,Quikling/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,Quikling/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,janebeckman/gpdb,lisakowen/gpdb,0x0FFF/gpdb,kaknikhil/gpdb,royc1/gpdb,kaknikhil/gpdb,adam8157/gpdb,rvs/gpdb,Quikling/gpdb,ahachete/gpdb,lisakowen/gpdb,Quikling/gpdb,greenplum-db/gpdb,50wu/gpdb,50wu/gpdb,yuanzhao/gpdb,lintzc/gpdb,ahachete/gpdb,zaksoup/gpdb,zaksoup/gpdb,royc1/gpdb,janebeckman/gpdb,Chibin/gpdb,kaknikhil/gpdb,xuegang/gpdb