HDF5  1.12.0
H5SMpkg.h
Go to the documentation of this file.
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  * Programmer: James Laird <jlaird@ncsa.uiuc.edu>
16  * Thursday, March 30, 2006
17  *
18  * Purpose: This file contains declarations which are visible only within
19  * the H5SM shared object header messages package. Source files
20  * outside the H5SM package should include H5SMprivate.h instead.
21  */
22 #if !(defined H5SM_FRIEND || defined H5SM_MODULE)
23 #error "Do not include this file outside the H5SM package!"
24 #endif
25 
26 #ifndef _H5SMpkg_H
27 #define _H5SMpkg_H
28 
29 /* Get package's private header */
30 #include "H5SMprivate.h" /* Shared Object Header Messages */
31 
32 /* Other private headers needed by this file */
33 #include "H5ACprivate.h" /* Metadata Cache */
34 #include "H5B2private.h" /* B-trees */
35 #include "H5HFprivate.h" /* Fractal heaps */
36 
37 
38 /****************************/
39 /* Package Macros */
40 /****************************/
41 
42 /* Size of checksum information (on disk) */
43 #define H5SM_SIZEOF_CHECKSUM 4
44 
45 #define H5SM_HEAP_LOC_SIZE ( \
46  (unsigned)4 /* Reference count */ \
47  + sizeof(H5O_fheap_id_t) /* size of heap ID on disk */ \
48  )
49 
50 #define H5SM_OH_LOC_SIZE(f) ( \
51  (unsigned)1 /* reserved (possible flags?) */ \
52  + (unsigned)1 /* message type ID */ \
53  + (unsigned)2 /* creation index of message in OH */ \
54  + H5F_SIZEOF_ADDR(f) /* address of OH */ \
55  )
56 
57 #define H5SM_SOHM_ENTRY_SIZE(f) ( \
58  (unsigned)1 /* Message location */ \
59  + (unsigned)4 /* Hash value */ \
60  + MAX(H5SM_HEAP_LOC_SIZE, H5SM_OH_LOC_SIZE(f)) /* Entry */ \
61  )
62 
63 #define H5SM_INDEX_HEADER_SIZE(f) ( \
64  (unsigned)1 /* Whether index is a list or B-tree */ \
65  + (unsigned)1 /* Version of index format */ \
66  + (unsigned)2 /* Type of messages stored in the index */ \
67  + (unsigned)4 /* Minimum size of messages to share */ \
68  + (unsigned)(3 * 2) /* B-tree cutoff, list cutoff, # of shared messages */ \
69  + H5F_SIZEOF_ADDR(f) /* Location of list or B-tree */ \
70  + H5F_SIZEOF_ADDR(f) /* Address of heap */ \
71  )
72 
73 /* Format overhead for all SOHM tree metadata in the file */
74 #define H5SM_METADATA_PREFIX_SIZE ( \
75  H5_SIZEOF_MAGIC /* Signature */ \
76  + H5SM_SIZEOF_CHECKSUM /* Checksum */ \
77  )
78 
79 #define H5SM_TABLE_SIZE(f) ( \
80  /* General metadata fields */ \
81  H5SM_METADATA_PREFIX_SIZE \
82  \
83  /* Indices */ \
84  + (H5F_SOHM_NINDEXES(f) * H5SM_INDEX_HEADER_SIZE(f)) \
85  )
86 
87 #define H5SM_LIST_SIZE(f, num_mesg) ( \
88  /* General metadata fields */ \
89  H5SM_METADATA_PREFIX_SIZE \
90  \
91  /* Message entries */ \
92  + (H5SM_SOHM_ENTRY_SIZE(f) * num_mesg) \
93  )
94 
95 #define H5SM_B2_NODE_SIZE 512
96 #define H5SM_B2_SPLIT_PERCENT 100
97 #define H5SM_B2_MERGE_PERCENT 40
98 
99 #define H5SM_LIST_VERSION 0 /* Version of Shared Object Header Message List Indexes */
100 
101 /****************************/
102 /* Package Typedefs */
103 /****************************/
104 
105 /* There are a number of Shared Object Header Message-specific structs here.
106  *
107  * The H5SM_master_table_t is pointed to by the file superblock. Since a file
108  * can have more than one SOHM index, this table collects all the indexes into
109  * one place. It holds an array of H5SM_index_header_t structs.
110  *
111  * An H5SM_index_header_t is actually the for a given index. It holds
112  * the number of messages in the index, the types of messages in the index,
113  * etc. It also records whether the index is a list or a b-tree, and has
114  * the address of the list or b-tree.
115  *
116  * If the index is a list, the address in the index header should be given
117  * to the cache, which can load it into a H5SM_list_t struct. This is mostly
118  * just a header for the cache information; it contains a pointer back to
119  * the index header and an unsorted array of messages.
120  *
121  * These messages are H5SM_sohm_t structs. They hold the actual SOHM's
122  * address, hash value, and refcount.
123  *
124  * If the index is a b-tree, the H5SM_index_header_t struct holds the address
125  * of the b-tree instead of the address of a H5SM_list_t. The B-tree's nodes
126  * are still 'H5SM_sohm_t's.
127  *
128  * H5SM_mesg_key_t structs are used to search lists and B-trees for a certain
129  * message. They correspond to a message that hasn't yet been written to
130  * disk.
131  */
132 
133 /* Where a message is stored */
134 typedef enum {
136  H5SM_IN_HEAP = 0, /* Message is stored in the heap */
137  H5SM_IN_OH /* Message is stored in an object header */
139 
140 /* Typedef for a record's location if it's stored in the heap */
141 typedef struct {
142  hsize_t ref_count; /* Number of times this message is used in the file */
143  H5O_fheap_id_t fheap_id; /* ID of the OHM in the fractal heap */
145 
146 /* Typedef for a SOHM index node */
147 typedef struct {
148  H5SM_storage_loc_t location; /* Type of message location */
149  uint32_t hash; /* Hash value for encoded OHM */
150  unsigned msg_type_id; /* Message's type ID */
151  union {
152  H5O_mesg_loc_t mesg_loc; /* Location of message in object header */
153  H5SM_heap_loc_t heap_loc; /* Heap ID for message in SOHM heap */
154  } u;
155 } H5SM_sohm_t;
156 
157 /* Types of message indices */
158 typedef enum {
160  H5SM_LIST, /* Index is an unsorted list */
161  H5SM_BTREE /* Index is a sorted B-tree */
163 
164 /* Typedef for a SOHM index header */
165 typedef struct {
166 /* Stored */
167  unsigned mesg_types; /* Bit flag vector of message types */
168  size_t min_mesg_size; /* number of messages being tracked */
169  size_t list_max; /* >= this many messages, index with a B-tree */
170  size_t btree_min; /* <= this many messages, index with a list again */
171  size_t num_messages; /* number of messages being tracked */
172  H5SM_index_type_t index_type; /* Is the index a list or a B-tree? */
173  haddr_t index_addr; /* Address of the actual index (list or B-tree) */
174  haddr_t heap_addr; /* Address of the fheap used to store shared messages */
175 
176 /* Not stored */
177  size_t list_size; /* Size of list index on disk */
179 
180 /* Typedef for a SOHM list */
181 typedef struct {
182  /* Information for H5AC cache functions, _must_ be first field in structure */
184 
185  H5SM_index_header_t *header; /* Pointer to the corresponding index header */
186  H5SM_sohm_t *messages; /* Actual list, stored as an array */
187 } H5SM_list_t;
188 
189 /* Typedef for shared object header message master table */
191  /* Information for H5AC cache functions, _must_ be first field in structure */
193 
194  size_t table_size; /* Size of table on disk */
195  unsigned num_indexes; /* Number of indexes */
196  H5SM_index_header_t *indexes; /* Array of num_indexes indexes */
197 };
198 
199 /* Typedef for searching an index (list or B-tree) */
200 typedef struct {
201  H5F_t *file; /* File in which sharing is happening */
202  H5HF_t *fheap; /* The heap for this message type, open. */
203  void *encoding; /* The message encoded, or NULL */
204  size_t encoding_size; /* Size of the encoding, or 0 */
205  H5SM_sohm_t message; /* The message to find/insert.
206  * If the message doesn't yet have a
207  * heap ID, the heap ID will be 0. */
209 
210 /*
211  * Data exchange structure to pass through the fractal heap layer for the
212  * H5HF_op function when computing a hash value for a message.
213  */
214 typedef struct {
215  /* downward (internal) */
216  unsigned type_id; /* Message type */
217 
218  /* upward */
219  uint32_t hash; /* Hash value */
221 
222 /* Typedef to increment a reference count in the B-tree */
223 typedef struct {
224  H5SM_mesg_key_t *key; /* IN: key for message being incremented */
225  H5O_fheap_id_t fheap_id; /* OUT: fheap ID of record */
227 
228 /* v2 B-tree client callback context */
229 typedef struct H5SM_bt2_ctx_t {
230  uint8_t sizeof_addr; /* Size of file addresses */
232 
233 /* Callback info for loading a shared message table index into the cache */
234 typedef struct H5SM_table_cache_ud_t {
235  H5F_t *f; /* File that shared message index stored as a table is in */
237 
238 /* Callback info for loading a shared message list index into the cache */
239 typedef struct H5SM_list_cache_ud_t {
240  H5F_t *f; /* File that shared message index stored as a table is in */
241  H5SM_index_header_t *header; /* Index header for this list */
243 
244 
245 /****************************/
246 /* Package Variables */
247 /****************************/
248 
249 /* Declare free lists to manage H5SM structs */
254 
256 
257 /****************************/
258 /* Package Prototypes */
259 /****************************/
260 
261 /* General routines */
262 H5_DLL ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id);
263 
264 /* Encode and decode routines, used for B-tree and cache encoding/decoding */
265 H5_DLL herr_t H5SM__message_compare(const void *rec1, const void *rec2, int *result);
266 H5_DLL herr_t H5SM__message_encode(uint8_t *raw, const void *native, void *ctx);
267 H5_DLL herr_t H5SM__message_decode(const uint8_t *raw, void *native, void *ctx);
268 
269 /* H5B2_remove_t callback to add messages to a list index */
270 H5_DLL herr_t H5SM_bt2_convert_to_list_op(const void * record, void *op_data);
271 
272 /* Fractal heap 'op' callback to compute hash value for message "in place" */
273 H5_DLL herr_t H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata);
274 
275 /* Routines to release data structures */
278 
279 /* Testing functions */
280 #ifdef H5SM_TESTING
281 H5_DLL herr_t H5SM__get_mesg_count_test(H5F_t *f, unsigned type_id, size_t *mesg_count);
282 #endif /* H5SM_TESTING */
283 
284 #endif /* _H5SMpkg_H */
285 
u
hsize_t u
Definition: H5EA.c:1007
H5SM_index_header_t
Definition: H5SMpkg.h:165
ssize_t
int ssize_t
Definition: H5public.h:167
H5SM_get_hash_fh_cb
H5_DLL herr_t H5SM_get_hash_fh_cb(const void *obj, size_t obj_len, void *_udata)
Definition: H5SM.c:1692
H5SM_sohm_t::hash
uint32_t hash
Definition: H5SMpkg.h:149
H5SM_list_cache_ud_t
Definition: H5SMpkg.h:239
H5SM_list_cache_ud_t
struct H5SM_list_cache_ud_t H5SM_list_cache_ud_t
H5SM_mesg_key_t::file
H5F_t * file
Definition: H5SMpkg.h:201
f
hdr f
Definition: H5EA.c:755
H5SM_list_t::header
H5SM_index_header_t * header
Definition: H5SMpkg.h:185
uint32_t
uint32_t
Definition: H5overflow.txt:38
H5SM_heap_loc_t::ref_count
hsize_t ref_count
Definition: H5SMpkg.h:142
H5SM_index_header_t::min_mesg_size
size_t min_mesg_size
Definition: H5SMpkg.h:168
H5SM_INDEX
H5_DLLVAR const H5B2_class_t H5SM_INDEX[1]
Definition: H5SMpkg.h:255
H5SM_mesg_key_t::encoding
void * encoding
Definition: H5SMpkg.h:203
haddr_t
CATCH haddr_t
Definition: H5EAdblock.c:162
H5SM_index_header_t::num_messages
size_t num_messages
Definition: H5SMpkg.h:171
H5SM_index_header_t::list_size
size_t list_size
Definition: H5SMpkg.h:177
result
Definition: H5Ztrans.c:67
H5SM_mesg_key_t
Definition: H5SMpkg.h:200
H5_DLLVAR
#define H5_DLLVAR
Definition: H5api_adpt.h:235
H5SM_mesg_key_t::fheap
H5HF_t * fheap
Definition: H5SMpkg.h:202
H5SM_list_free
herr_t H5SM_list_free(H5SM_list_t *list)
Definition: H5SM.c:2510
uint8_t
unsigned char uint8_t
Definition: H5private.h:429
H5SM_bt2_convert_to_list_op
H5_DLL herr_t H5SM_bt2_convert_to_list_op(const void *record, void *op_data)
Definition: H5SMbtree2.c:233
H5SM_IN_OH
@ H5SM_IN_OH
Definition: H5SMpkg.h:137
H5FL_EXTERN
H5FL_EXTERN(H5SM_master_table_t)
H5SM_table_cache_ud_t
struct H5SM_table_cache_ud_t H5SM_table_cache_ud_t
H5SM__message_compare
H5_DLL herr_t H5SM__message_compare(const void *rec1, const void *rec2, int *result)
Definition: H5SMmessage.c:188
H5SM_LIST
@ H5SM_LIST
Definition: H5SMpkg.h:160
H5SM_NO_LOC
@ H5SM_NO_LOC
Definition: H5SMpkg.h:135
H5SM_heap_loc_t::fheap_id
H5O_fheap_id_t fheap_id
Definition: H5SMpkg.h:143
H5O_mesg_loc_t
Definition: H5Oprivate.h:256
H5SM_fh_ud_gh_t::type_id
unsigned type_id
Definition: H5SMpkg.h:216
H5SM__message_decode
H5_DLL herr_t H5SM__message_decode(const uint8_t *raw, void *native, void *ctx)
Definition: H5SMmessage.c:335
H5SM_fh_ud_gh_t
Definition: H5SMpkg.h:214
H5SM_list_cache_ud_t::header
H5SM_index_header_t * header
Definition: H5SMpkg.h:241
H5SM_BTREE
@ H5SM_BTREE
Definition: H5SMpkg.h:161
H5SM_index_type_t
H5SM_index_type_t
Definition: H5SMpkg.h:158
H5SM_table_cache_ud_t
Definition: H5SMpkg.h:234
H5SM_index_header_t::mesg_types
unsigned mesg_types
Definition: H5SMpkg.h:167
H5ACprivate.h
H5SM_master_table_t::indexes
H5SM_index_header_t * indexes
Definition: H5SMpkg.h:196
H5SM_storage_loc_t
H5SM_storage_loc_t
Definition: H5SMpkg.h:134
H5SM_IN_HEAP
@ H5SM_IN_HEAP
Definition: H5SMpkg.h:136
H5SM__get_mesg_count_test
herr_t H5SM__get_mesg_count_test(H5F_t *f, unsigned type_id, size_t *mesg_count)
Definition: H5SMtest.c:77
H5SM_list_t::cache_info
H5AC_info_t cache_info
Definition: H5SMpkg.h:183
H5SM_sohm_t
Definition: H5SMpkg.h:147
H5SM_sohm_t::location
H5SM_storage_loc_t location
Definition: H5SMpkg.h:148
H5SM_index_header_t::list_max
size_t list_max
Definition: H5SMpkg.h:169
H5SM_master_table_t::cache_info
H5AC_info_t cache_info
Definition: H5SMpkg.h:192
H5SM__message_encode
H5_DLL herr_t H5SM__message_encode(uint8_t *raw, const void *native, void *ctx)
Definition: H5SMmessage.c:291
H5SM_bt2_ctx_t::sizeof_addr
uint8_t sizeof_addr
Definition: H5SMpkg.h:230
H5SM_incr_ref_opdata::fheap_id
H5O_fheap_id_t fheap_id
Definition: H5SMpkg.h:225
H5_DLL
#define H5_DLL
Definition: H5api_adpt.h:234
H5SM_sohm_t::mesg_loc
H5O_mesg_loc_t mesg_loc
Definition: H5SMpkg.h:152
H5SM_BADTYPE
@ H5SM_BADTYPE
Definition: H5SMpkg.h:159
H5O_fheap_id_t
Definition: H5Oprivate.h:146
H5SM_incr_ref_opdata::key
H5SM_mesg_key_t * key
Definition: H5SMpkg.h:224
H5SM_get_index
H5_DLL ssize_t H5SM_get_index(const H5SM_master_table_t *table, unsigned type_id)
Definition: H5SM.c:313
H5SM_mesg_key_t::message
H5SM_sohm_t message
Definition: H5SMpkg.h:205
H5SM_index_header_t::btree_min
size_t btree_min
Definition: H5SMpkg.h:170
H5SM_list_t::messages
H5SM_sohm_t * messages
Definition: H5SMpkg.h:186
H5SM_master_table_t::table_size
size_t table_size
Definition: H5SMpkg.h:194
H5SM_incr_ref_opdata
Definition: H5SMpkg.h:223
H5SM_bt2_ctx_t
Definition: H5SMpkg.h:229
H5F_t
Definition: H5Fpkg.h:374
H5SM_table_cache_ud_t::f
H5F_t * f
Definition: H5SMpkg.h:235
H5SMprivate.h
herr_t
int herr_t
Definition: H5public.h:128
H5SM_index_header_t::heap_addr
haddr_t heap_addr
Definition: H5SMpkg.h:174
H5C_cache_entry_t
Definition: H5Cprivate.h:1597
H5SM_master_table_t
Definition: H5SMpkg.h:190
H5HF_t
Definition: H5HFpkg.h:459
H5FL_ARR_EXTERN
H5FL_ARR_EXTERN(H5SM_index_header_t)
hsize_t
hsize_t
Definition: H5overflow.txt:44
H5B2_class_t
Definition: H5B2private.h:82
H5SM_table_free
herr_t H5SM_table_free(H5SM_master_table_t *table)
Definition: H5SM.c:2481
H5HFprivate.h
H5SM_index_header_t::index_addr
haddr_t index_addr
Definition: H5SMpkg.h:173
H5SM_mesg_key_t::encoding_size
size_t encoding_size
Definition: H5SMpkg.h:204
H5SM_list_cache_ud_t::f
H5F_t * f
Definition: H5SMpkg.h:240
H5SM_index_header_t::index_type
H5SM_index_type_t index_type
Definition: H5SMpkg.h:172
H5SM_fh_ud_gh_t::hash
uint32_t hash
Definition: H5SMpkg.h:219
H5SM_sohm_t::heap_loc
H5SM_heap_loc_t heap_loc
Definition: H5SMpkg.h:153
H5B2private.h
H5SM_sohm_t::msg_type_id
unsigned msg_type_id
Definition: H5SMpkg.h:150
H5SM_bt2_ctx_t
struct H5SM_bt2_ctx_t H5SM_bt2_ctx_t
H5SM_master_table_t::num_indexes
unsigned num_indexes
Definition: H5SMpkg.h:195
H5SM_list_t
Definition: H5SMpkg.h:181
H5SM_heap_loc_t
Definition: H5SMpkg.h:141