MySQL 9.6.0
Source Code Documentation
mysql_lock_free_hash.h
Go to the documentation of this file.
1/* Copyright (c) 2025, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef MYSQL_LOCK_FREE_HASH_H
25#define MYSQL_LOCK_FREE_HASH_H
26
27#include <lf_types.h>
30
31/**
32 Hash colleciton handle.
33*/
35
36/**
37 Hash collection access handle.
38*/
40
41/**
42 @ingroup group_components_services_inventory
43
44 Lock free hashing collection.
45*/
46BEGIN_SERVICE_DEFINITION(mysql_lock_free_hash)
47
48/**
49 Initialize lock free hash.
50
51 @return Initialized hash handle.
52*/
54 (uint element_size, uint flags, uint key_offset, uint key_length,
58/**
59 Destroy lock free hash.
60
61 @param hash Hash handle.
62*/
64
65/**
66 Get pins for search.
67
68 @param hash Hash handle.
69
70 @return Search pins handle.
71*/
73
74/**
75 Find hash element corresponding to the key.
76
77 @param hash The hash to search element in.
78 @param pins Pins for the calling thread which were earlier
79 obtained from this hash using lf_hash_get_pins().
80 @param dat Key
81 @param length Key length
82
83 @retval A pointer to an element with the given key (if a hash is not unique
84 and there're many elements with this key - the "first" matching
85 element).
86 @retval NULL - if nothing is found
87 @retval MY_LF_ERRPTR - if OOM
88
89 @note Uses pins[0..2]. On return pins[0..1] are removed and pins[2]
90 is used to pin object found. It is also not removed in case when
91 object is not found/error occurs but pin value is undefined in
92 this case.
93 So calling search_unpin() is mandatory after call to this function
94 in case of both success and failure.
95*/
96DECLARE_METHOD(void *, search,
97 (LF_HASH_h hash, LF_PINS_h pins, const void *data,
98 ulong length));
99
100/**
101 Remove data from hash.
102
103 @param hash Hash handle.
104 @param pins Search pins.
105 @param data Search data.
106 @param length Data length.
107
108 @return Zero value on success.
109*/
111 (LF_HASH_h hash, LF_PINS_h pins, const void *data, uint length));
112
113/**
114 Find random hash element which satisfies condition specified by
115 match function.
116
117 @param hash Hash to search element in.
118 @param pins Pins for calling thread to be used during search
119 and for pinning its result.
120 @param match Pointer to match function. This function takes
121 pointer to object stored in hash as parameter
122 and returns 0 if object doesn't satisfy its
123 condition (and non-0 value if it does).
124 @param rand_val Random value to be used for selecting hash
125 bucket from which search in sort-ordered
126 list needs to be started.
127 @param match_arg Argument passed to match function.
128
129 @retval A pointer to a random element matching condition.
130 @retval NULL - if nothing is found
131 @retval MY_LF_ERRPTR - OOM.
132
133 @note This function follows the same pinning protocol as lf_hash_search(),
134 i.e. uses pins[0..2]. On return pins[0..1] are removed and pins[2]
135 is used to pin object found. It is also not removed in case when
136 object is not found/error occurs but its value is undefined in
137 this case.
138 So calling lf_hash_unpin() is mandatory after call to this function
139 in case of both success and failure.
140*/
141DECLARE_METHOD(void *, random_match,
142 (LF_HASH_h hash, LF_PINS_h pins, lf_hash_match_func *match,
143 uint rand_val, void *match_arg));
144
145/**
146 Unpin search pins.
147
148 @param pins Pins handle.
149*/
150DECLARE_METHOD(void, search_unpin, (LF_PINS_h pins));
151
152/**
153 Put pins into a hash.
154
155 @param pins Pins handle.
156*/
157DECLARE_METHOD(void, put_pins, (LF_PINS_h pins));
158
159/**
160 Insert data into a hash.
161
162 @param hash Hash handle.
163 @param pins Pins handle.
164 @param data Data pointer.
165
166 @retval 0 Inserted.
167 @retval 1 Failed. Unique key conflict.
168 @retval -1 Failed. Out of memory.
169*/
170DECLARE_METHOD(int, insert, (LF_HASH_h hash, LF_PINS_h pins, const void *data));
171
172/**
173 Hash entry header size.
174
175 @return Overhead value.
176*/
177DECLARE_METHOD(int, overhead, ());
178
179END_SERVICE_DEFINITION(mysql_lock_free_hash)
180
181#endif /* MYSQL_LOCK_FREE_HASH_H */
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:566
int destroy(azio_stream *s)
Definition: azio.cc:372
static int flags[50]
Definition: hp_test1.cc:40
void lf_hash_init_func(uchar *dst, const uchar *src)
Definition: lf_types.h:52
void lf_allocator_func(uchar *)
Definition: lf_types.h:48
const uchar *(* hash_get_key_function)(const uchar *arg, size_t *length)
Callback for extracting key and key length from user data in a LF_HASH.
Definition: lf_types.h:43
int lf_hash_match_func(const uchar *el, void *arg)
Definition: lf_types.h:50
struct LF_HASH_h_imp * LF_HASH_h
Hash colleciton handle.
Definition: mysql_lock_free_hash.h:34
struct LF_PINS_h_imp * LF_PINS_h
Hash collection access handle.
Definition: mysql_lock_free_hash.h:39
struct CHARSET_INFO_h_imp * CHARSET_INFO_h
Definition: mysql_string.h:41
const std::string charset("charset")
void insert(dd::cache::SPI_lru_cache_owner_ptr &c, dd::Object_id id)
Definition: dictionary_client.cc:3077
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:137
#define DECLARE_METHOD(retval, name, args)
Declares a method as a part of the Service definition.
Definition: service.h:103
#define END_SERVICE_DEFINITION(name)
A macro to end the last Service definition started with the BEGIN_SERVICE_DEFINITION macro.
Definition: service.h:91
#define BEGIN_SERVICE_DEFINITION(name)
Declares a new Service.
Definition: service.h:86
#define DEFINE_SERVICE_HANDLE(name)
Defines an object type that is meant for carrying handles to the implementation-specific objects used...
Definition: service.h:129
#define DECLARE_BOOL_METHOD(name, args)
Declares a method that returns bool as a part of the Service definition.
Definition: service.h:112