filehash/ffdb_page.c
int
ffdb_rearrage_pages_on_open (ffdb_htab_t* hashp)
{
  pgno_t oldfirst, oldlast, newfirst, newlast;
  pgno_t lastdpage;
  unsigned int num_page_moved;

  /* Check whether any pages has been moved when the database is closed */
  if (hashp->hdr.num_moved_pages == 0)
    return 0;
  
  if (hashp->hdr.max_bucket == hashp->hdr.high_mask) 
    return 0;

  /* We have not used every single hash bucket at the last level */
  BUCKET_TO_PAGE(hashp->hdr.max_bucket + 1, oldfirst);

  /* We will get number of moved page from meta header which
   * records how many pages are moved when this file was closed
   */
  num_page_moved = hashp->hdr.num_moved_pages;
  
  oldlast = oldfirst + num_page_moved - 1;


  /* We figure out where these page are going to */
  newlast = hashp->hdr.spares[hashp->hdr.ovfl_point + 1] - 1;
  newfirst = newlast - num_page_moved + 1;

#if 1
  fprintf (stderr, "Page can be moved starting at page %d and end at %d on last level %d to page %d to %d\n",
	   oldfirst, oldlast, hashp->hdr.ovfl_point, newfirst, newlast);
#endif


  /* Move data pages first */
  lastdpage = _ffdb_move_pages (hashp, HASH_DATA_PAGE, oldfirst, oldlast,
				newfirst, newlast);

  /* move overflow page next */
  _ffdb_move_pages (hashp, HASH_BUCKET_PAGE, oldfirst, oldlast,
		    newfirst, newlast);
  
  _ffdb_move_pages (hashp, HASH_FREE_PAGE, oldfirst, oldlast,
		    newfirst, newlast);

  /* If there are no data pages moved, unlikely but possible */
  if (lastdpage == INVALID_PGNO) 
    hashp->curr_dpage = ffdb_last_data_page (hashp, newfirst - 1);

  /* Reset the number of moved pages */
  hashp->hdr.num_moved_pages = 0;

  /* Clean out those pages from page cache to make memory
   * the same as if there are no pages have been here
   */
  _ffdb_remove_pages (hashp, oldfirst, oldlast);

  return 0;
}
/**
 * Optional to reorganize the pages to move pages occuping
 * reguler hash pages when the database expects new inserts
 */
Optional to reorganize the pages to move pages occuping
reguler hash pages when the database expects new inserts
Optional to reorganize the pages to move pages occuping reguler hash pages when the database expects new inserts
int
ffdb_rearrage_pages_on_open (ffdb_htab_t* hashp)
{
  pgno_t oldfirst, oldlast, newfirst, newlast;
  pgno_t lastdpage;
  unsigned int num_page_moved;
  if (hashp->hdr.num_moved_pages == 0)
    return 0;
  if (hashp->hdr.max_bucket == hashp->hdr.high_mask) 
    return 0;
  BUCKET_TO_PAGE(hashp->hdr.max_bucket + 1, oldfirst);
  num_page_moved = hashp->hdr.num_moved_pages;
  oldlast = oldfirst + num_page_moved - 1;
  newlast = hashp->hdr.spares[hashp->hdr.ovfl_point + 1] - 1;
  newfirst = newlast - num_page_moved + 1;
#if 1
  fprintf (stderr, "Page can be moved starting at page %d and end at %d on last level %d to page %d to %d\n",
	   oldfirst, oldlast, hashp->hdr.ovfl_point, newfirst, newlast);
#endif
  lastdpage = _ffdb_move_pages (hashp, HASH_DATA_PAGE, oldfirst, oldlast,
				newfirst, newlast);
  _ffdb_move_pages (hashp, HASH_BUCKET_PAGE, oldfirst, oldlast,
		    newfirst, newlast);
  _ffdb_move_pages (hashp, HASH_FREE_PAGE, oldfirst, oldlast,
		    newfirst, newlast);
  if (lastdpage == INVALID_PGNO) 
    hashp->curr_dpage = ffdb_last_data_page (hashp, newfirst - 1);
  hashp->hdr.num_moved_pages = 0;
  _ffdb_remove_pages (hashp, oldfirst, oldlast);
  return 0;
}
int ffdb_rearrage_pages_on_open ( ffdb_htab_t * hashp ) { pgno_t oldfirst , oldlast , newfirst , newlast ; pgno_t lastdpage ; unsigned int num_page_moved ; if ( hashp -> hdr . num_moved_pages == 0 ) return 0 ; if ( hashp -> hdr . max_bucket == hashp -> hdr . high_mask ) return 0 ; BUCKET_TO_PAGE ( hashp -> hdr . max_bucket + 1 , oldfirst ) ; num_page_moved = hashp -> hdr . num_moved_pages ; oldlast = oldfirst + num_page_moved - 1 ; newlast = hashp -> hdr . spares [ hashp -> hdr . ovfl_point + 1 ] - 1 ; newfirst = newlast - num_page_moved + 1 ; #if 1 fprintf ( stderr , " \n " , oldfirst , oldlast , hashp -> hdr . ovfl_point , newfirst , newlast ) ; #endif lastdpage = _ffdb_move_pages ( hashp , HASH_DATA_PAGE , oldfirst , oldlast , newfirst , newlast ) ; _ffdb_move_pages ( hashp , HASH_BUCKET_PAGE , oldfirst , oldlast , newfirst , newlast ) ; _ffdb_move_pages ( hashp , HASH_FREE_PAGE , oldfirst , oldlast , newfirst , newlast ) ; if ( lastdpage == INVALID_PGNO ) hashp -> curr_dpage = ffdb_last_data_page ( hashp , newfirst - 1 ) ; hashp -> hdr . num_moved_pages = 0 ; _ffdb_remove_pages ( hashp , oldfirst , oldlast ) ; return 0 ; }
Optional to reorganize the pages to move pages occuping
 reguler hash pages when the database expects new inserts
Optional to reorganize the pages to move pages occuping reguler hash pages when the database expects new inserts
/* Check whether any pages has been moved when the database is closed */ /* We have not used every single hash bucket at the last level */ /* We will get number of moved page from meta header which
   * records how many pages are moved when this file was closed
   */ /* We figure out where these page are going to */ /* Move data pages first */ /* move overflow page next */ /* If there are no data pages moved, unlikely but possible */ /* Reset the number of moved pages */ /* Clean out those pages from page cache to make memory
   * the same as if there are no pages have been here
   */