filehash/ffdb_page.c
int 
ffdb_split_bucket (ffdb_htab_t* hashp, unsigned int oldbucket,
		   unsigned int newbucket, int isdoubling)
{
  unsigned int i;
  FFDB_DBT key;
  void *oldpagep, *temp_pagep;
  pgno_t oldpage, nextpage, tp;
  unsigned char *kdata = 0;
  ffdb_datap_t* datap = 0;
  int base_page = 1;

  /* This page may not be in memory or in use so FFDB_CREATE flag has to be 
   * used
   */
  oldpagep = ffdb_get_page (hashp, oldbucket, HASH_BUCKET_PAGE, FFDB_CREATE, &oldpage);
  if (!oldpagep) {
    fprintf (stderr, "Cannot find page for bucket %d\n", oldbucket);
    return -1;
  }

  /* get split buffer pointer */
  temp_pagep = hashp->split_buf;
  /* Copy the old page content to the temp page */
  memcpy (temp_pagep, oldpagep, hashp->hdr.bsize);

  /* reset the old page */
  _ffdb_init_page (hashp, oldpagep, oldpage, HASH_BUCKET_PAGE);
  ffdb_put_page (hashp, oldpagep, HASH_BUCKET_PAGE, 1);

  while (temp_pagep != 0) {
    /* get key and data pointer value */
    for (i = 0; i < NUM_ENT(temp_pagep); i++) {
      kdata = KEY(temp_pagep, i);
      key.data = kdata;
      key.size = KEY_LEN(temp_pagep, i);
      datap = DATAP(temp_pagep, i);

      /* Now we need to put this key and data pointer pair */
      if (_ffdb_call_hash (hashp, key.data, key.size) == oldbucket) 
	/* this stays with old page without changing data pointer value */
	_ffdb_add_key_datap_to_bucket (hashp, &key, datap, oldbucket);
      else 
	_ffdb_add_key_datap_to_bucket (hashp, &key, datap, newbucket);
    }
    
    /* get next page number */
    nextpage = NEXT_PGNO(temp_pagep);
    
    /* if this is the base page (regular hash page) */
    if (base_page) 
      base_page = 0;
    else  /* free overflow page */ 
      ffdb_delete_page (hashp, temp_pagep, HASH_OVFL_PAGE, isdoubling);
    
    if (nextpage != INVALID_PGNO) 
      temp_pagep = ffdb_get_page (hashp, nextpage, HASH_OVFL_PAGE, 0, &tp);
    else
      break;
  }
  return 0;
}
/**
 * Split a bucket: this happens when a bucket is full. This bucket may not be 
 * splitted right away (overflow pages needed), but it will eventually 
 * will be splitted
 */
Split a bucket: this happens when a bucket is full. This bucket may not be
splitted right away (overflow pages needed), but it will eventually
will be splitted
Split a bucket : this happens when a bucket is full . This bucket may not be splitted right away ( overflow pages needed ) but it will eventually will be splitted
int 
ffdb_split_bucket (ffdb_htab_t* hashp, unsigned int oldbucket,
		   unsigned int newbucket, int isdoubling)
{
  unsigned int i;
  FFDB_DBT key;
  void *oldpagep, *temp_pagep;
  pgno_t oldpage, nextpage, tp;
  unsigned char *kdata = 0;
  ffdb_datap_t* datap = 0;
  int base_page = 1;
  oldpagep = ffdb_get_page (hashp, oldbucket, HASH_BUCKET_PAGE, FFDB_CREATE, &oldpage);
  if (!oldpagep) {
    fprintf (stderr, "Cannot find page for bucket %d\n", oldbucket);
    return -1;
  }
  temp_pagep = hashp->split_buf;
  memcpy (temp_pagep, oldpagep, hashp->hdr.bsize);
  _ffdb_init_page (hashp, oldpagep, oldpage, HASH_BUCKET_PAGE);
  ffdb_put_page (hashp, oldpagep, HASH_BUCKET_PAGE, 1);
  while (temp_pagep != 0) {
    for (i = 0; i < NUM_ENT(temp_pagep); i++) {
      kdata = KEY(temp_pagep, i);
      key.data = kdata;
      key.size = KEY_LEN(temp_pagep, i);
      datap = DATAP(temp_pagep, i);
      if (_ffdb_call_hash (hashp, key.data, key.size) == oldbucket) 
	_ffdb_add_key_datap_to_bucket (hashp, &key, datap, oldbucket);
      else 
	_ffdb_add_key_datap_to_bucket (hashp, &key, datap, newbucket);
    }
    nextpage = NEXT_PGNO(temp_pagep);
    if (base_page) 
      base_page = 0;
    else   
      ffdb_delete_page (hashp, temp_pagep, HASH_OVFL_PAGE, isdoubling);
    if (nextpage != INVALID_PGNO) 
      temp_pagep = ffdb_get_page (hashp, nextpage, HASH_OVFL_PAGE, 0, &tp);
    else
      break;
  }
  return 0;
}
int ffdb_split_bucket ( ffdb_htab_t * hashp , unsigned int oldbucket , unsigned int newbucket , int isdoubling ) { unsigned int i ; FFDB_DBT key ; void * oldpagep , * temp_pagep ; pgno_t oldpage , nextpage , tp ; unsigned char * kdata = 0 ; ffdb_datap_t * datap = 0 ; int base_page = 1 ; oldpagep = ffdb_get_page ( hashp , oldbucket , HASH_BUCKET_PAGE , FFDB_CREATE , & oldpage ) ; if ( ! oldpagep ) { fprintf ( stderr , " \n " , oldbucket ) ; return -1 ; } temp_pagep = hashp -> split_buf ; memcpy ( temp_pagep , oldpagep , hashp -> hdr . bsize ) ; _ffdb_init_page ( hashp , oldpagep , oldpage , HASH_BUCKET_PAGE ) ; ffdb_put_page ( hashp , oldpagep , HASH_BUCKET_PAGE , 1 ) ; while ( temp_pagep != 0 ) { for ( i = 0 ; i < NUM_ENT ( temp_pagep ) ; i ++ ) { kdata = KEY ( temp_pagep , i ) ; key . data = kdata ; key . size = KEY_LEN ( temp_pagep , i ) ; datap = DATAP ( temp_pagep , i ) ; if ( _ffdb_call_hash ( hashp , key . data , key . size ) == oldbucket ) _ffdb_add_key_datap_to_bucket ( hashp , & key , datap , oldbucket ) ; else _ffdb_add_key_datap_to_bucket ( hashp , & key , datap , newbucket ) ; } nextpage = NEXT_PGNO ( temp_pagep ) ; if ( base_page ) base_page = 0 ; else ffdb_delete_page ( hashp , temp_pagep , HASH_OVFL_PAGE , isdoubling ) ; if ( nextpage != INVALID_PGNO ) temp_pagep = ffdb_get_page ( hashp , nextpage , HASH_OVFL_PAGE , 0 , & tp ) ; else break ; } return 0 ; }
Split a bucket: this happens when a bucket is full.
Split a bucket : this happens when a bucket is full .
/* This page may not be in memory or in use so FFDB_CREATE flag has to be 
   * used
   */ /* get split buffer pointer */ /* Copy the old page content to the temp page */ /* reset the old page */ /* get key and data pointer value */ /* Now we need to put this key and data pointer pair */ /* this stays with old page without changing data pointer value */ /* get next page number */ /* if this is the base page (regular hash page) */ /* free overflow page */