1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /*-------------------------------------------------------------------------
15 *
16 * Created: H5B2dbg.c
17 * Feb 2 2005
18 * Quincey Koziol <koziol@ncsa.uiuc.edu>
19 *
20 * Purpose: Dump debugging information about a v2 B-tree.
21 *
22 *-------------------------------------------------------------------------
23 */
24
25 /****************/
26 /* Module Setup */
27 /****************/
28
29 #include "H5B2module.h" /* This source code file is part of the H5B2 module */
30
31
32 /***********/
33 /* Headers */
34 /***********/
35 #include "H5private.h" /* Generic Functions */
36 #include "H5B2pkg.h" /* v2 B-trees */
37 #include "H5Eprivate.h" /* Error handling */
38 #include "H5FLprivate.h" /* Free Lists */
39
40 /****************/
41 /* Local Macros */
42 /****************/
43
44
45 /******************/
46 /* Local Typedefs */
47 /******************/
48
49
50 /********************/
51 /* Package Typedefs */
52 /********************/
53
54
55 /********************/
56 /* Local Prototypes */
57 /********************/
58
59
60 /*********************/
61 /* Package Variables */
62 /*********************/
63
64
65 /*****************************/
66 /* Library Private Variables */
67 /*****************************/
68
69
70 /*******************/
71 /* Local Variables */
72 /*******************/
73
74
75 /*-------------------------------------------------------------------------
76 * Function: H5B2__hdr_debug
77 *
78 * Purpose: Prints debugging info about a B-tree header.
79 *
80 * Return: Non-negative on success/Negative on failure
81 *
82 * Programmer: Quincey Koziol
83 * koziol@ncsa.uiuc.edu
84 * Feb 2 2005
85 *
86 *-------------------------------------------------------------------------
87 */
88 herr_t
H5B2__hdr_debug(H5F_t * f,hid_t dxpl_id,haddr_t addr,FILE * stream,int indent,int fwidth,const H5B2_class_t * type,haddr_t obj_addr)89 H5B2__hdr_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth,
90 const H5B2_class_t *type, haddr_t obj_addr)
91 {
92 H5B2_hdr_t *hdr = NULL; /* B-tree header info */
93 unsigned u; /* Local index variable */
94 char temp_str[128]; /* Temporary string, for formatting */
95 herr_t ret_value = SUCCEED; /* Return value */
96
97 FUNC_ENTER_PACKAGE
98
99 /*
100 * Check arguments.
101 */
102 HDassert(f);
103 HDassert(H5F_addr_defined(addr));
104 HDassert(H5F_addr_defined(obj_addr));
105 HDassert(stream);
106 HDassert(indent >= 0);
107 HDassert(fwidth >= 0);
108 HDassert(type);
109
110 /* Load the B-tree header */
111 if(NULL == (hdr = H5B2__hdr_protect(f, dxpl_id, addr, f, H5AC__READ_ONLY_FLAG)))
112 HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree header")
113
114 /* Set file pointer for this B-tree operation */
115 hdr->f = f;
116
117 /* Print opening message */
118 HDfprintf(stream, "%*sv2 B-tree Header...\n", indent, "");
119
120 /*
121 * Print the values.
122 */
123 HDfprintf(stream, "%*s%-*s %s (%u)\n", indent, "", fwidth,
124 "Tree type ID:", hdr->cls->name, (unsigned)hdr->cls->id);
125 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
126 "Size of node:",
127 (unsigned)hdr->node_size);
128 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
129 "Size of raw (disk) record:",
130 (unsigned)hdr->rrec_size);
131 HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
132 "Dirty flag:",
133 hdr->cache_info.is_dirty ? "True" : "False");
134 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
135 "Depth:",
136 hdr->depth);
137 HDfprintf(stream, "%*s%-*s %Hu\n", indent, "", fwidth,
138 "Number of records in tree:",
139 hdr->root.all_nrec);
140 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
141 "Number of records in root node:",
142 hdr->root.node_nrec);
143 HDfprintf(stream, "%*s%-*s %a\n", indent, "", fwidth,
144 "Address of root node:",
145 hdr->root.addr);
146 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
147 "Split percent:",
148 hdr->split_percent);
149 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
150 "Merge percent:",
151 hdr->merge_percent);
152
153 /* Print relevant node info */
154 HDfprintf(stream, "%*sNode Info: (max_nrec/split_nrec/merge_nrec)\n", indent, "");
155 for(u = 0; u < (unsigned)(hdr->depth + 1); u++) {
156 HDsnprintf(temp_str, sizeof(temp_str), "Depth %u:", u);
157 HDfprintf(stream, "%*s%-*s (%u/%u/%u)\n", indent + 3, "", MAX(0, fwidth - 3),
158 temp_str,
159 hdr->node_info[u].max_nrec, hdr->node_info[u].split_nrec, hdr->node_info[u].merge_nrec);
160 } /* end for */
161
162 done:
163 if(hdr && H5B2__hdr_unprotect(hdr, dxpl_id, H5AC__NO_FLAGS_SET) < 0)
164 HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release v2 B-tree header")
165
166 FUNC_LEAVE_NOAPI(ret_value)
167 } /* end H5B2__hdr_debug() */
168
169
170 /*-------------------------------------------------------------------------
171 * Function: H5B2__int_debug
172 *
173 * Purpose: Prints debugging info about a B-tree internal node
174 *
175 * Return: Non-negative on success/Negative on failure
176 *
177 * Programmer: Quincey Koziol
178 * koziol@ncsa.uiuc.edu
179 * Feb 4 2005
180 *
181 *-------------------------------------------------------------------------
182 */
183 herr_t
H5B2__int_debug(H5F_t * f,hid_t dxpl_id,haddr_t addr,FILE * stream,int indent,int fwidth,const H5B2_class_t * type,haddr_t hdr_addr,unsigned nrec,unsigned depth,haddr_t obj_addr)184 H5B2__int_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth,
185 const H5B2_class_t *type, haddr_t hdr_addr, unsigned nrec, unsigned depth, haddr_t obj_addr)
186 {
187 H5B2_hdr_t *hdr = NULL; /* B-tree header */
188 H5B2_internal_t *internal = NULL; /* B-tree internal node */
189 H5B2_node_ptr_t node_ptr; /* Fake node pointer for protect */
190 unsigned u; /* Local index variable */
191 char temp_str[128]; /* Temporary string, for formatting */
192 herr_t ret_value=SUCCEED; /* Return value */
193
194 FUNC_ENTER_PACKAGE
195
196 /*
197 * Check arguments.
198 */
199 HDassert(f);
200 HDassert(H5F_addr_defined(addr));
201 HDassert(stream);
202 HDassert(indent >= 0);
203 HDassert(fwidth >= 0);
204 HDassert(type);
205 HDassert(H5F_addr_defined(hdr_addr));
206 HDassert(H5F_addr_defined(obj_addr));
207 HDassert(nrec > 0);
208
209 /* Load the B-tree header */
210 if(NULL == (hdr = H5B2__hdr_protect(f, dxpl_id, hdr_addr, f, H5AC__READ_ONLY_FLAG)))
211 HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load v2 B-tree header")
212
213 /* Set file pointer for this B-tree operation */
214 hdr->f = f;
215
216 /*
217 * Load the B-tree internal node
218 */
219 H5_CHECK_OVERFLOW(depth, unsigned, uint16_t);
220 node_ptr.addr = addr;
221 H5_CHECKED_ASSIGN(node_ptr.node_nrec, unsigned, nrec, uint16_t)
222 if(NULL == (internal = H5B2__protect_internal(hdr, dxpl_id, NULL, &node_ptr, (uint16_t)depth, FALSE, H5AC__READ_ONLY_FLAG)))
223 HGOTO_ERROR(H5E_BTREE, H5E_CANTLOAD, FAIL, "unable to load B-tree internal node")
224
225 /* Print opening message */
226 HDfprintf(stream, "%*sv2 B-tree Internal Node...\n", indent, "");
227
228 /*
229 * Print the values.
230 */
231 HDfprintf(stream, "%*s%-*s %s (%u)\n", indent, "", fwidth,
232 "Tree type ID:", hdr->cls->name, (unsigned)hdr->cls->id);
233 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
234 "Size of node:",
235 (unsigned)hdr->node_size);
236 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
237 "Size of raw (disk) record:",
238 (unsigned)hdr->rrec_size);
239 HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
240 "Dirty flag:",
241 internal->cache_info.is_dirty ? "True" : "False");
242 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
243 "Number of records in node:",
244 internal->nrec);
245
246 /* Print all node pointers and records */
247 for(u = 0; u < internal->nrec; u++) {
248 /* Print node pointer */
249 HDsnprintf(temp_str, sizeof(temp_str), "Node pointer #%u: (all/node/addr)", u);
250 HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
251 temp_str,
252 internal->node_ptrs[u].all_nrec,
253 internal->node_ptrs[u].node_nrec,
254 internal->node_ptrs[u].addr);
255
256 /* Print record */
257 HDsnprintf(temp_str, sizeof(temp_str), "Record #%u:", u);
258 HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
259 temp_str);
260 HDassert(H5B2_INT_NREC(internal, hdr, u));
261 (void)(type->debug)(stream, indent + 6, MAX (0, fwidth-6), H5B2_INT_NREC(internal, hdr, u), hdr->cb_ctx);
262 } /* end for */
263
264 /* Print final node pointer */
265 HDsnprintf(temp_str, sizeof(temp_str), "Node pointer #%u: (all/node/addr)", u);
266 HDfprintf(stream, "%*s%-*s (%Hu/%u/%a)\n", indent + 3, "", MAX(0, fwidth - 3),
267 temp_str,
268 internal->node_ptrs[u].all_nrec,
269 internal->node_ptrs[u].node_nrec,
270 internal->node_ptrs[u].addr);
271
272 done:
273 if(hdr && H5B2__hdr_unprotect(hdr, dxpl_id, H5AC__NO_FLAGS_SET) < 0)
274 HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release v2 B-tree header")
275 if(internal && H5AC_unprotect(f, dxpl_id, H5AC_BT2_INT, addr, internal, H5AC__NO_FLAGS_SET) < 0)
276 HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree internal node")
277
278 FUNC_LEAVE_NOAPI(ret_value)
279 } /* end H5B2__int_debug() */
280
281
282 /*-------------------------------------------------------------------------
283 * Function: H5B2__leaf_debug
284 *
285 * Purpose: Prints debugging info about a B-tree leaf node
286 *
287 * Return: Non-negative on success/Negative on failure
288 *
289 * Programmer: Quincey Koziol
290 * koziol@ncsa.uiuc.edu
291 * Feb 7 2005
292 *
293 *-------------------------------------------------------------------------
294 */
295 herr_t
H5B2__leaf_debug(H5F_t * f,hid_t dxpl_id,haddr_t addr,FILE * stream,int indent,int fwidth,const H5B2_class_t * type,haddr_t hdr_addr,unsigned nrec,haddr_t obj_addr)296 H5B2__leaf_debug(H5F_t *f, hid_t dxpl_id, haddr_t addr, FILE *stream, int indent, int fwidth,
297 const H5B2_class_t *type, haddr_t hdr_addr, unsigned nrec, haddr_t obj_addr)
298 {
299 H5B2_hdr_t *hdr = NULL; /* B-tree header */
300 H5B2_leaf_t *leaf = NULL; /* B-tree leaf node */
301 H5B2_node_ptr_t node_ptr; /* Fake node pointer for protect */
302 unsigned u; /* Local index variable */
303 char temp_str[128]; /* Temporary string, for formatting */
304 herr_t ret_value = SUCCEED; /* Return value */
305
306 FUNC_ENTER_PACKAGE
307
308 /*
309 * Check arguments.
310 */
311 HDassert(f);
312 HDassert(H5F_addr_defined(addr));
313 HDassert(stream);
314 HDassert(indent >= 0);
315 HDassert(fwidth >= 0);
316 HDassert(type);
317 HDassert(H5F_addr_defined(hdr_addr));
318 HDassert(H5F_addr_defined(obj_addr));
319 HDassert(nrec > 0);
320
321 /* Load the B-tree header */
322 if(NULL == (hdr = H5B2__hdr_protect(f, dxpl_id, hdr_addr, f, H5AC__READ_ONLY_FLAG)))
323 HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect v2 B-tree header")
324
325 /* Set file pointer for this B-tree operation */
326 hdr->f = f;
327
328 /*
329 * Load the B-tree leaf node
330 */
331 H5_CHECK_OVERFLOW(nrec, unsigned, uint16_t);
332 node_ptr.addr = addr;
333 H5_CHECKED_ASSIGN(node_ptr.node_nrec, unsigned, nrec, uint16_t)
334 if(NULL == (leaf = H5B2__protect_leaf(hdr, dxpl_id, NULL, &node_ptr, FALSE, H5AC__READ_ONLY_FLAG)))
335 HGOTO_ERROR(H5E_BTREE, H5E_CANTPROTECT, FAIL, "unable to protect B-tree leaf node")
336
337 /* Print opening message */
338 HDfprintf(stream, "%*sv2 B-tree Leaf Node...\n", indent, "");
339
340 /*
341 * Print the values.
342 */
343 HDfprintf(stream, "%*s%-*s %s (%u)\n", indent, "", fwidth,
344 "Tree type ID:", hdr->cls->name, (unsigned)hdr->cls->id);
345 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
346 "Size of node:",
347 (unsigned)hdr->node_size);
348 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
349 "Size of raw (disk) record:",
350 (unsigned)hdr->rrec_size);
351 HDfprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
352 "Dirty flag:",
353 leaf->cache_info.is_dirty ? "True" : "False");
354 HDfprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
355 "Number of records in node:",
356 leaf->nrec);
357
358 /* Print all node pointers and records */
359 for(u = 0; u < leaf->nrec; u++) {
360 /* Print record */
361 HDsnprintf(temp_str, sizeof(temp_str), "Record #%u:", u);
362 HDfprintf(stream, "%*s%-*s\n", indent + 3, "", MAX(0, fwidth - 3),
363 temp_str);
364 HDassert(H5B2_LEAF_NREC(leaf, hdr, u));
365 (void)(type->debug)(stream, indent + 6, MAX (0, fwidth-6), H5B2_LEAF_NREC(leaf, hdr, u), hdr->cb_ctx);
366 } /* end for */
367
368 done:
369 if(hdr && H5B2__hdr_unprotect(hdr, dxpl_id, H5AC__NO_FLAGS_SET) < 0)
370 HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree header")
371 if(leaf && H5AC_unprotect(f, dxpl_id, H5AC_BT2_LEAF, addr, leaf, H5AC__NO_FLAGS_SET) < 0)
372 HDONE_ERROR(H5E_BTREE, H5E_PROTECT, FAIL, "unable to release B-tree leaf node")
373
374 FUNC_LEAVE_NOAPI(ret_value)
375 } /* end H5B2__leaf_debug() */
376
377