H5B2pkg.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  * Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
00018  *              Monday, January 31, 2005
00019  *
00020  * Purpose:     This file contains declarations which are visible only within
00021  *              the H5B2 package.  Source files outside the H5B2 package should
00022  *              include H5B2private.h instead.
00023  */
00024 #ifndef H5B2_PACKAGE
00025 #error "Do not include this file outside the H5B2 package!"
00026 #endif
00027 
00028 #ifndef _H5B2pkg_H
00029 #define _H5B2pkg_H
00030 
00031 /* Get package's private header */
00032 #include "H5B2private.h"
00033 
00034 /* Other private headers needed by this file */
00035 #include "H5ACprivate.h"        /* Metadata cache                       */
00036 #include "H5FLprivate.h"        /* Free Lists                           */
00037 #include "H5RCprivate.h"        /* Reference counted object functions   */
00038 
00039 /**************************/
00040 /* Package Private Macros */
00041 /**************************/
00042 
00043 /* Size of storage for number of records per node (on disk) */
00044 #define H5B2_SIZEOF_RECORDS_PER_NODE    2
00045 
00046 /* Size of a "tree pointer" (on disk) */
00047 /* (essentially, the largest internal pointer allowed) */
00048 #define H5B2_TREE_POINTER_SIZE(f)       (H5F_SIZEOF_ADDR(f)+H5B2_SIZEOF_RECORDS_PER_NODE+H5F_SIZEOF_SIZE(f))
00049 
00050 /* Size of a internal node pointer (on disk) */
00051 #define H5B2_INT_POINTER_SIZE(f, s, d) (                                      \
00052     H5F_SIZEOF_ADDR(f)          /* Address of child node */                   \
00053     + (s)->max_nrec_size        /* # of records in child node */              \
00054     + (s)->node_info[(d) - 1].cum_max_nrec_size /* Total # of records in child & below */ \
00055     )
00056 
00057 /* Size of checksum information (on disk) */
00058 #define H5B2_SIZEOF_CHKSUM      4
00059 
00060 /* Format overhead for all v2 B-tree metadata in the file */
00061 #define H5B2_METADATA_PREFIX_SIZE (                                           \
00062     H5_SIZEOF_MAGIC   /* Signature */                                         \
00063     + 1 /* Version */                                                         \
00064     + 1 /* Tree type */                                                       \
00065     + H5B2_SIZEOF_CHKSUM /* Metadata checksum */                              \
00066     )
00067 
00068 /* Size of the v2 B-tree header on disk */
00069 #define H5B2_HEADER_SIZE(f)     (                                             \
00070     /* General metadata fields */                                             \
00071     H5B2_METADATA_PREFIX_SIZE                                                 \
00072                                                                               \
00073     /* Header specific fields */                                              \
00074     + 4 /* Node size, in bytes */                                             \
00075     + 2 /* Record size, in bytes */                                           \
00076     + 2 /* Depth of tree */                                                   \
00077     + 1 /* Split % of full (as integer, ie. "98" means 98%) */                \
00078     + 1 /* Merge % of full (as integer, ie. "98" means 98%) */                \
00079     + H5B2_TREE_POINTER_SIZE(f)  /* Node pointer to root node in tree */      \
00080     )
00081 
00082 /* Size of the v2 B-tree internal node prefix */
00083 #define H5B2_INT_PREFIX_SIZE (                                                \
00084     /* General metadata fields */                                             \
00085     H5B2_METADATA_PREFIX_SIZE                                                 \
00086                                                                               \
00087     /* Header specific fields */                                              \
00088     /* <none> */                                                              \
00089     )
00090 
00091 /* Size of the v2 B-tree leaf node prefix */
00092 #define H5B2_LEAF_PREFIX_SIZE (                                               \
00093     /* General metadata fields */                                             \
00094     H5B2_METADATA_PREFIX_SIZE                                                 \
00095                                                                               \
00096     /* Header specific fields */                                              \
00097     /* <none> */                                                              \
00098     )
00099 
00100 /* Macro to retrieve pointer to i'th native record for native record buffer */
00101 #define H5B2_NAT_NREC(b, shared, idx)  ((b) + (shared)->nat_off[(idx)])
00102 
00103 /* Macro to retrieve pointer to i'th native record for internal node */
00104 #define H5B2_INT_NREC(i, shared, idx)  H5B2_NAT_NREC((i)->int_native, (shared), (idx))
00105 
00106 /* Macro to retrieve pointer to i'th native record for leaf node */
00107 #define H5B2_LEAF_NREC(l, shared, idx)  H5B2_NAT_NREC((l)->leaf_native, (shared), (idx))
00108 
00109 
00110 /****************************/
00111 /* Package Private Typedefs */
00112 /****************************/
00113 
00114 /* A "node pointer" to another B-tree node */
00115 typedef struct {
00116     haddr_t     addr;           /* Address of other node */
00117     unsigned    node_nrec;      /* Number of records used in node pointed to */
00118     hsize_t     all_nrec;       /* Number of records in node pointed to and all it's children */
00119 } H5B2_node_ptr_t;
00120 
00121 /* Information about a node at a given depth */
00122 typedef struct {
00123     unsigned    max_nrec;       /* Max. number of records in node */
00124     unsigned    split_nrec;     /* Number of records to split node at */
00125     unsigned    merge_nrec;     /* Number of records to merge node at */
00126     hsize_t     cum_max_nrec;   /* Cumulative max. # of records below this node's depth */
00127     unsigned char cum_max_nrec_size; /* Size to store cumulative max. # of records for this node (in bytes) */
00128     H5FL_fac_head_t *nat_rec_fac;   /* Factory for native record blocks */
00129     H5FL_fac_head_t *node_ptr_fac;  /* Factory for node pointer blocks */
00130 } H5B2_node_info_t;
00131 
00132 /* Each B-tree has certain information that can be shared across all
00133  * the instances of nodes in that B-tree.
00134  */
00135 typedef struct H5B2_shared_t {
00136     /* Shared internal data structures */
00137     const H5B2_class_t  *type;   /* Type of tree                             */
00138     uint8_t             *page;   /* Common disk page for I/O */
00139     size_t              *nat_off;   /* Array of offsets of native records */
00140     H5B2_node_info_t    *node_info; /* Table of node info structs for current depth of B-tree */
00141 
00142     /* Information set by user (stored) */
00143     unsigned    split_percent;  /* Percent full at which to split the node, when inserting */
00144     unsigned    merge_percent;  /* Percent full at which to merge the node, when deleting */
00145     size_t      node_size;      /* Size of B-tree nodes, in bytes             */
00146     size_t      rrec_size;      /* Size of "raw" (on disk) record, in bytes   */
00147 
00148     /* Dynamic information (stored) */
00149     unsigned    depth;          /* B-tree's overall depth                     */
00150 
00151     /* Derived information from user's information */
00152     unsigned char max_nrec_size; /* Size to store max. # of records in any node (in bytes) */
00153 } H5B2_shared_t;
00154 
00155 /* The B-tree information */
00156 typedef struct H5B2_t {
00157     /* Information for H5AC cache functions, _must_ be first field in structure */
00158     H5AC_info_t cache_info;
00159 
00160     /* Internal B-tree information */
00161     H5B2_node_ptr_t root;       /* Node pointer to root node in B-tree        */
00162     H5RC_t      *shared;        /* Ref-counted shared info                    */
00163 } H5B2_t;
00164 
00165 /* B-tree leaf node information */
00166 typedef struct H5B2_leaf_t {
00167     /* Information for H5AC cache functions, _must_ be first field in structure */
00168     H5AC_info_t cache_info;
00169 
00170     /* Internal B-tree information */
00171     H5RC_t      *shared;        /* Ref-counted shared info                    */
00172     uint8_t     *leaf_native;   /* Pointer to native records                  */
00173     unsigned    nrec;           /* Number of records in node                  */
00174 } H5B2_leaf_t;
00175 
00176 /* B-tree internal node information */
00177 typedef struct H5B2_internal_t {
00178     /* Information for H5AC cache functions, _must_ be first field in structure */
00179     H5AC_info_t cache_info;
00180 
00181     /* Internal B-tree information */
00182     H5RC_t      *shared;        /* Ref-counted shared info                    */
00183     uint8_t     *int_native;    /* Pointer to native records                  */
00184     H5B2_node_ptr_t *node_ptrs; /* Pointer to node pointers                   */
00185     unsigned    nrec;           /* Number of records in node                  */
00186     unsigned    depth;          /* Depth of this node in the B-tree           */
00187 } H5B2_internal_t;
00188 
00189 /* User data for metadata cache 'load' callback */
00190 typedef struct {
00191     H5RC_t *bt2_shared;         /* Ref counter for shared B-tree info */
00192     unsigned nrec;              /* Number of records in node to load */
00193     unsigned depth;             /* Depth of node to load */
00194 } H5B2_int_load_ud1_t;
00195 
00196 #ifdef H5B2_TESTING
00197 /* Node information for testing */
00198 typedef struct {
00199     unsigned depth;             /* Depth of node */
00200     unsigned nrec;              /* Number of records in node */
00201 } H5B2_node_info_test_t;
00202 #endif /* H5B2_TESTING */
00203 
00204 
00205 /*****************************/
00206 /* Package Private Variables */
00207 /*****************************/
00208 
00209 /* H5B2 header inherits cache-like properties from H5AC */
00210 H5_DLLVAR const H5AC_class_t H5AC_BT2_HDR[1];
00211 
00212 /* H5B2 internal node inherits cache-like properties from H5AC */
00213 H5_DLLVAR const H5AC_class_t H5AC_BT2_INT[1];
00214 
00215 /* H5B2 leaf node inherits cache-like properties from H5AC */
00216 H5_DLLVAR const H5AC_class_t H5AC_BT2_LEAF[1];
00217 
00218 /* Declare a free list to manage the H5B2_t struct */
00219 H5FL_EXTERN(H5B2_t);
00220 
00221 /* Declare a free list to manage the H5B2_internal_t struct */
00222 H5FL_EXTERN(H5B2_internal_t);
00223 
00224 /* Declare a free list to manage the H5B2_leaf_t struct */
00225 H5FL_EXTERN(H5B2_leaf_t);
00226 
00227 /* Internal v2 B-tree testing class */
00228 #ifdef H5B2_TESTING
00229 H5_DLLVAR const H5B2_class_t H5B2_TEST[1];
00230 #endif /* H5B2_TESTING */
00231 
00232 
00233 /******************************/
00234 /* Package Private Prototypes */
00235 /******************************/
00236 
00237 /* Routines for managing shared B-tree info */
00238 H5_DLL herr_t H5B2_shared_init(H5F_t *f, H5B2_t *bt2, const H5B2_class_t *type,
00239     unsigned depth, size_t node_size, size_t rrec_size,
00240     unsigned split_percent, unsigned merge_percent);
00241 
00242 /* Routines for operating on internal nodes */
00243 H5_DLL H5B2_internal_t *H5B2_protect_internal(H5F_t *f, hid_t dxpl_id,
00244     H5RC_t *bt2_shared, haddr_t addr, unsigned nrec, unsigned depth,
00245     H5AC_protect_t rw);
00246 
00247 /* Routines for allocating nodes */
00248 H5_DLL herr_t H5B2_split_root(H5F_t *f, hid_t dxpl_id, H5B2_t *bt2,
00249     unsigned *bt2_flags_ptr);
00250 H5_DLL herr_t H5B2_create_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00251     H5B2_node_ptr_t *node_ptr);
00252 
00253 /* Routines for inserting records */
00254 H5_DLL herr_t H5B2_insert_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00255     unsigned depth, unsigned *parent_cache_info_flags_ptr,
00256     H5B2_node_ptr_t *curr_node_ptr, void *udata);
00257 H5_DLL herr_t H5B2_insert_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00258     H5B2_node_ptr_t *curr_node_ptr, void *udata);
00259 
00260 /* Routines for iterating over nodes/records */
00261 H5_DLL herr_t H5B2_iterate_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00262     unsigned depth, const H5B2_node_ptr_t *curr_node, H5B2_operator_t op,
00263     void *op_data);
00264 H5_DLL herr_t H5B2_iterate_size_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00265     unsigned depth, const H5B2_node_ptr_t *curr_node, hsize_t *op_data);
00266 
00267 /* Routines for locating records */
00268 H5_DLL int H5B2_locate_record(const H5B2_class_t *type, unsigned nrec,
00269     size_t *rec_off, const uint8_t *native, const void *udata, unsigned *idx);
00270 H5_DLL herr_t H5B2_neighbor_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00271     unsigned depth, H5B2_node_ptr_t *curr_node_ptr, void *neighbor_loc,
00272     H5B2_compare_t comp, void *udata, H5B2_found_t op, void *op_data);
00273 H5_DLL herr_t H5B2_neighbor_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00274     H5B2_node_ptr_t *curr_node_ptr, void *neighbor_loc,
00275     H5B2_compare_t comp, void *udata, H5B2_found_t op, void *op_data);
00276 
00277 /* Routines for removing records */
00278 H5_DLL herr_t H5B2_remove_internal(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00279     hbool_t *depth_decreased, void *swap_loc, unsigned depth, H5AC_info_t *parent_cache_info,
00280     hbool_t * parent_cache_info_dirtied_ptr, H5B2_node_ptr_t *curr_node_ptr, void *udata,
00281     H5B2_remove_t op, void *op_data);
00282 H5_DLL herr_t H5B2_remove_leaf(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00283     H5B2_node_ptr_t *curr_node_ptr, void *udata, H5B2_remove_t op,
00284     void *op_data);
00285 H5_DLL herr_t H5B2_remove_internal_by_idx(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00286     hbool_t *depth_decreased, void *swap_loc, unsigned depth, H5AC_info_t *parent_cache_info,
00287     hbool_t * parent_cache_info_dirtied_ptr, H5B2_node_ptr_t *curr_node_ptr, hsize_t idx,
00288     H5B2_remove_t op, void *op_data);
00289 H5_DLL herr_t H5B2_remove_leaf_by_idx(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00290     H5B2_node_ptr_t *curr_node_ptr, unsigned idx, H5B2_remove_t op,
00291     void *op_data);
00292 
00293 /* Routines for deleting nodes */
00294 H5_DLL herr_t H5B2_delete_node(H5F_t *f, hid_t dxpl_id, H5RC_t *bt2_shared,
00295     unsigned depth, const H5B2_node_ptr_t *curr_node, H5B2_remove_t op,
00296     void *op_data);
00297 
00298 /* Metadata cache callbacks */
00299 H5_DLL herr_t H5B2_cache_hdr_dest(H5F_t *f, H5B2_t *b);
00300 H5_DLL herr_t H5B2_cache_leaf_dest(H5F_t *f, H5B2_leaf_t *l);
00301 H5_DLL herr_t H5B2_cache_internal_dest(H5F_t *f, H5B2_internal_t *i);
00302 
00303 /* Debugging routines for dumping file structures */
00304 H5_DLL herr_t H5B2_hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
00305     FILE *stream, int indent, int fwidth, const H5B2_class_t *type);
00306 H5_DLL herr_t H5B2_int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
00307     FILE *stream, int indent, int fwidth, const H5B2_class_t *type,
00308     haddr_t hdr_addr, unsigned nrec, unsigned depth);
00309 H5_DLL herr_t H5B2_leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr,
00310     FILE *stream, int indent, int fwidth, const H5B2_class_t *type,
00311     haddr_t hdr_addr, unsigned nrec);
00312 
00313 /* Testing routines */
00314 #ifdef H5B2_TESTING
00315 H5_DLL herr_t H5B2_get_root_addr_test(H5F_t *f, hid_t dxpl_id,
00316     const H5B2_class_t *type, haddr_t addr, haddr_t *root_addr);
00317 H5_DLL int H5B2_get_node_depth_test(H5F_t *f, hid_t dxpl_id,
00318     const H5B2_class_t *type, haddr_t addr, void *udata);
00319 H5_DLL herr_t H5B2_get_node_info_test(H5F_t *f, hid_t dxpl_id,
00320     const H5B2_class_t *type, haddr_t addr, void *udata,
00321     H5B2_node_info_test_t *ninfo);
00322 #endif /* H5B2_TESTING */
00323 
00324 #endif /* _H5B2pkg_H */
00325