From 160b7415080616740565a31e4a2450bb2336dfb6 Mon Sep 17 00:00:00 2001
From: Amit Kapila <amit.kapila@enterprisedb.com>
Date: Thu, 16 Feb 2017 17:57:54 +0530
Subject: [PATCH 2/5] Expose an API hashinitbitmapbuffer.

This API will be used to initialize bitmap page buffer.
This patch will be used by future patches to enable WAL
logging.
---
 src/backend/access/hash/hashovfl.c | 36 ++++++++++++++++++++++++++++++++++++
 src/include/access/hash.h          |  1 +
 2 files changed, 37 insertions(+)

diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c
index 52491e0..cee0efd 100644
--- a/src/backend/access/hash/hashovfl.c
+++ b/src/backend/access/hash/hashovfl.c
@@ -620,6 +620,42 @@ _hash_initbitmap(Relation rel, HashMetaPage metap, BlockNumber blkno,
 
 
 /*
+ *	_hash_initbitmapbuffer()
+ *
+ *	 Initialize a new bitmap page.  All bits in the new bitmap page are set to
+ *	 "1", indicating "in use".
+ */
+void
+_hash_initbitmapbuffer(Buffer buf, uint16 bmsize, bool initpage)
+{
+	Page		pg;
+	HashPageOpaque op;
+	uint32	   *freep;
+
+	pg = BufferGetPage(buf);
+
+	/* initialize the page */
+	if (initpage)
+		_hash_pageinit(pg, BufferGetPageSize(buf));
+
+	/* initialize the page's special space */
+	op = (HashPageOpaque) PageGetSpecialPointer(pg);
+	op->hasho_prevblkno = InvalidBlockNumber;
+	op->hasho_nextblkno = InvalidBlockNumber;
+	op->hasho_bucket = -1;
+	op->hasho_flag = LH_BITMAP_PAGE;
+	op->hasho_page_id = HASHO_PAGE_ID;
+
+	/* set all of the bits to 1 */
+	freep = HashPageGetBitmap(pg);
+	MemSet(freep, 0xFF, bmsize);
+
+	/* Set pd_lower just past the end of the bitmap page data. */
+	((PageHeader) pg)->pd_lower = ((char *) freep + bmsize) - (char *) pg;
+}
+
+
+/*
  *	_hash_squeezebucket(rel, bucket)
  *
  *	Try to squeeze the tuples onto pages occurring earlier in the
diff --git a/src/include/access/hash.h b/src/include/access/hash.h
index 5767deb..9c0b79f 100644
--- a/src/include/access/hash.h
+++ b/src/include/access/hash.h
@@ -313,6 +313,7 @@ extern BlockNumber _hash_freeovflpage(Relation rel, Buffer bucketbuf, Buffer ovf
 			 Size *tups_size, uint16 nitups, BufferAccessStrategy bstrategy);
 extern void _hash_initbitmap(Relation rel, HashMetaPage metap,
 				 BlockNumber blkno, ForkNumber forkNum);
+extern void _hash_initbitmapbuffer(Buffer buf, uint16 bmsize, bool initpage);
 extern void _hash_squeezebucket(Relation rel,
 					Bucket bucket, BlockNumber bucket_blkno,
 					Buffer bucket_buf,
-- 
1.8.4.msysgit.0

