{
RelationMetapage meta;
+ if (relation->rd_metapage == NULL)
+ RelationBuildMetadata(relation);
PageSetRelationMetapage(page);
-
meta = BlindGetRelationMeta(page);
+ memcpy(meta, relation->rd_metapage, sizeof(RelationMetapageData));
+}
+
+/*
+ * Build metadata for a new relation.
+ */
+void
+RelationBuildMetadata(Relation relation)
+{
+ RelationMetapage meta;
+
+ /* The metadata shouldn't already be initialized. */
+ Assert(relation->rd_metapage == NULL);
+
+ /* Allocate memory for the data. */
+ meta = (RelationMetapage) MemoryContextAllocZero(CacheMemoryContext,
+ sizeof(RelationMetapageData));
+
+ /* Initialize. */
meta->rmp_magic = METAPAGE_MAGIC;
meta->rmp_version = METAPAGE_VERSION;
meta->rmp_dboid = relation->rd_node.dbNode;
meta->rmp_minlayout = PG_PAGE_LAYOUT_VERSION;
meta->rmp_maxlayout = PG_PAGE_LAYOUT_VERSION;
meta->rmp_relfilenode_time = (pg_time_t) time(NULL);
+
+ /* Save it. */
+ relation->rd_metapage = meta;
}
/*
* If the relation has a metapage, read it.
*
* XXX: It's pretty annoying to have to call RelationGetNumberOfBlocks.
- * Can't we have an RBM_ERROR option for ReadBufferExtended?
+ * Can't we have an RBM_FAIL option for ReadBufferExtended?
*/
if (RelationGetNumberOfBlocks(relation) > METAPAGE_BLKNO)
{
#include <fcntl.h>
#include <unistd.h>
+#include "access/metapage.h"
#include "access/reloptions.h"
#include "access/sysattr.h"
#include "access/transam.h"
RelationInitPhysicalAddr(rel);
+ /* XXX: Not for heaps yet. */
+ if (relkind == RELKIND_INDEX)
+ RelationBuildMetadata(rel);
+
/*
* Okay to insert into the relcache hash tables.
*/