filehash/ffdb_hash.c
static int
_ffdb_hdestroy (ffdb_htab_t* hashp)
{
  int save_errno = 0;

  if (hashp->rearrange_pages && hashp->save_file)
    ffdb_rearrage_pages_on_close (hashp);

#ifdef _FFDB_STATISTICS
  { 
    int i;
    fprintf(stderr, "hdestroy: accesses %u collisions %u\n",
	    hash_accesses, hash_collisions);
    fprintf(stderr,
	    "hdestroy: expansions %u\n", hash_expansions);
    fprintf(stderr,
	    "hdestroy: overflows %u\n", hash_overflows);
    fprintf(stderr,
	    "hdestroy: big key/data pages %u\n", hash_bigpages);
    fprintf(stderr,
	    "keys %u max bucket %d\n", hashp->hdr.nkeys, hashp->hdr.max_bucket);

    fprintf (stderr,
	     " Number of pages moved %d\n", hashp->hdr.num_moved_pages);
    
    for (i = 0; i < NCACHED; i++)
      fprintf(stderr,
		    "spares[%d] = %d\n", i, hashp->hdr.spares[i]);

    for (i = 0; i < NCACHED; i++)
      fprintf(stderr,
		    "freepages[%d] = %d\n", i, hashp->hdr.free_pages[i]);

    fprintf (stderr, "Average ffactor = %d\n", hashp->hdr.nkeys/(hashp->hdr.max_bucket + 1));
  }
#endif

  /* flush meta information header to disk */
  if (_ffdb_flush_meta (hashp) != 0)
    if (save_errno == 0)
      save_errno = errno;

  /* close the pagepool */
#ifdef _FFDB_STATISTICS
  ffdb_pagepool_stat (hashp->mp);
#endif
  ffdb_pagepool_sync (hashp->mp);
  ffdb_pagepool_close (hashp->mp);

  /* Reduce file size if possible */
  if (hashp->rearrange_pages)
    ffdb_reduce_filesize (hashp);

  if (hashp->fp != -1)
    close (hashp->fp);

  if (hashp->fname)
    free (hashp->fname);

  /* free allocated memory */
  if (hashp->split_buf)
    free(hashp->split_buf);
  if (hashp->bigdata_buf)
    free(hashp->bigdata_buf);
  if (hashp->bigkey_buf)
    free(hashp->bigkey_buf);

  if (save_errno) {
    errno = save_errno;
    return -1;
  }
  return 0;
}
/**
 * This is the routine called by hash close
 * lock is held by other routines
 */
This is the routine called by hash close
lock is held by other routines
This is the routine called by hash close lock is held by other routines
static int
_ffdb_hdestroy (ffdb_htab_t* hashp)
{
  int save_errno = 0;
  if (hashp->rearrange_pages && hashp->save_file)
    ffdb_rearrage_pages_on_close (hashp);
#ifdef _FFDB_STATISTICS
  { 
    int i;
    fprintf(stderr, "hdestroy: accesses %u collisions %u\n",
	    hash_accesses, hash_collisions);
    fprintf(stderr,
	    "hdestroy: expansions %u\n", hash_expansions);
    fprintf(stderr,
	    "hdestroy: overflows %u\n", hash_overflows);
    fprintf(stderr,
	    "hdestroy: big key/data pages %u\n", hash_bigpages);
    fprintf(stderr,
	    "keys %u max bucket %d\n", hashp->hdr.nkeys, hashp->hdr.max_bucket);
    fprintf (stderr,
	     " Number of pages moved %d\n", hashp->hdr.num_moved_pages);
    for (i = 0; i < NCACHED; i++)
      fprintf(stderr,
		    "spares[%d] = %d\n", i, hashp->hdr.spares[i]);
    for (i = 0; i < NCACHED; i++)
      fprintf(stderr,
		    "freepages[%d] = %d\n", i, hashp->hdr.free_pages[i]);
    fprintf (stderr, "Average ffactor = %d\n", hashp->hdr.nkeys/(hashp->hdr.max_bucket + 1));
  }
#endif
  if (_ffdb_flush_meta (hashp) != 0)
    if (save_errno == 0)
      save_errno = errno;
#ifdef _FFDB_STATISTICS
  ffdb_pagepool_stat (hashp->mp);
#endif
  ffdb_pagepool_sync (hashp->mp);
  ffdb_pagepool_close (hashp->mp);
  if (hashp->rearrange_pages)
    ffdb_reduce_filesize (hashp);
  if (hashp->fp != -1)
    close (hashp->fp);
  if (hashp->fname)
    free (hashp->fname);
  if (hashp->split_buf)
    free(hashp->split_buf);
  if (hashp->bigdata_buf)
    free(hashp->bigdata_buf);
  if (hashp->bigkey_buf)
    free(hashp->bigkey_buf);
  if (save_errno) {
    errno = save_errno;
    return -1;
  }
  return 0;
}
static int _ffdb_hdestroy ( ffdb_htab_t * hashp ) { int save_errno = 0 ; if ( hashp -> rearrange_pages && hashp -> save_file ) ffdb_rearrage_pages_on_close ( hashp ) ; #ifdef _FFDB_STATISTICS { int i ; fprintf ( stderr , " \n " , hash_accesses , hash_collisions ) ; fprintf ( stderr , " \n " , hash_expansions ) ; fprintf ( stderr , " \n " , hash_overflows ) ; fprintf ( stderr , " \n " , hash_bigpages ) ; fprintf ( stderr , " \n " , hashp -> hdr . nkeys , hashp -> hdr . max_bucket ) ; fprintf ( stderr , " \n " , hashp -> hdr . num_moved_pages ) ; for ( i = 0 ; i < NCACHED ; i ++ ) fprintf ( stderr , " \n " , i , hashp -> hdr . spares [ i ] ) ; for ( i = 0 ; i < NCACHED ; i ++ ) fprintf ( stderr , " \n " , i , hashp -> hdr . free_pages [ i ] ) ; fprintf ( stderr , " \n " , hashp -> hdr . nkeys / ( hashp -> hdr . max_bucket + 1 ) ) ; } #endif if ( _ffdb_flush_meta ( hashp ) != 0 ) if ( save_errno == 0 ) save_errno = errno ; #ifdef _FFDB_STATISTICS ffdb_pagepool_stat ( hashp -> mp ) ; #endif ffdb_pagepool_sync ( hashp -> mp ) ; ffdb_pagepool_close ( hashp -> mp ) ; if ( hashp -> rearrange_pages ) ffdb_reduce_filesize ( hashp ) ; if ( hashp -> fp != -1 ) close ( hashp -> fp ) ; if ( hashp -> fname ) free ( hashp -> fname ) ; if ( hashp -> split_buf ) free ( hashp -> split_buf ) ; if ( hashp -> bigdata_buf ) free ( hashp -> bigdata_buf ) ; if ( hashp -> bigkey_buf ) free ( hashp -> bigkey_buf ) ; if ( save_errno ) { errno = save_errno ; return -1 ; } return 0 ; }
This is the routine called by hash close
 lock is held by other routines
This is the routine called by hash close lock is held by other routines
/* flush meta information header to disk */ /* close the pagepool */ /* Reduce file size if possible */ /* free allocated memory */