MySQL  8.0.27
Source Code Documentation
xcom_cache.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2021, Oracle and/or its affiliates.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License, version 2.0,
5  as published by the Free Software Foundation.
6 
7  This program is also distributed with certain software (including
8  but not limited to OpenSSL) that is licensed under separate terms,
9  as designated in a particular file or component or in included license
10  documentation. The authors of MySQL hereby grant you an additional
11  permission to link the program and your derivative works with the
12  separately licensed software that they have included with MySQL.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License, version 2.0, for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef XCOM_CACHE_H
24 #define XCOM_CACHE_H
25 
26 #include <stddef.h>
27 
28 #include "xcom/simset.h"
29 #include "xcom/site_struct.h"
30 #include "xcom/xcom_profile.h"
31 #include "xdr_gen/xcom_vp.h"
32 
33 /*
34 We require that the number of elements in the cache is big enough enough that
35 it is always possible to find instances that are not busy.
36 Under normal circumstances the number of busy instances will be
37 less than event_horizon, since the proposers only considers
38 instances which belong to the local node.
39 A node may start proposing no_ops for instances belonging
40 to other nodes, meaning that event_horizon * NSERVERS instances may be
41 involved. However, for the time being, proposing a no_op for an instance
42 will not mark it as busy. This may change in the future, so a safe upper
43 limit on the number of nodes marked as busy is event_horizon * NSERVERS.
44 */
45 #define MIN_LENGTH MIN_CACHE_SIZE /* Also Default value */
46 #define INCREMENT MIN_LENGTH /* Total number of slots to add/remove */
47 
48 #define is_cached(x) (hash_get(x) != NULL)
49 
50 struct lru_machine;
51 typedef struct lru_machine lru_machine;
52 
53 struct stack_machine;
54 typedef struct stack_machine stack_machine;
55 
56 struct pax_machine;
57 typedef struct pax_machine pax_machine;
58 
59 #define p_events \
60  X(paxos_prepare), X(paxos_ack_prepare), X(paxos_accept), \
61  X(paxos_ack_accept), X(paxos_learn), X(paxos_start), X(paxos_tout), \
62  X(last_p_event)
63 
64 #define X(a) a
66 typedef enum paxos_event paxos_event;
67 #undef X
68 
69 struct paxos_fsm_state;
70 typedef struct paxos_fsm_state paxos_fsm_state;
71 
72 /* Function pointer corresponding to a state. Return 1 if execution should
73  * continue, 0 otherwise */
74 typedef int (*paxos_fsm_fp)(pax_machine *paxos, site_def const *site,
75  paxos_event event, pax_msg *mess);
76 
77 /* Function pointer and name */
80  char const *state_name;
81 };
82 
83 extern int paxos_fsm_idle(pax_machine *paxos, site_def const *site,
84  paxos_event event, pax_msg *mess);
85 
86 // Set current Paxos state and name of state (for tracing) in pax_machine object
87 #define SET_PAXOS_FSM_STATE(obj, s) \
88  do { \
89  (obj)->state.state_fp = s; \
90  (obj)->state.state_name = #s; \
91  } while (0)
92 
93 /* Definition of a Paxos instance */
94 struct pax_machine {
98  synode_no synode;
99  double last_modified; /* Start time */
100  linkage rv; /* Tasks may sleep on this until something interesting happens */
101  linkage watchdog; /* Used for timeouts in Paxos */
102 
103  struct {
104  ballot bal; /* The current ballot we are working on */
105  bit_set *prep_nodeset; /* Nodes which have answered my prepare */
106  ballot sent_prop;
107  bit_set *prop_nodeset; /* Nodes which have answered my propose */
108  pax_msg *msg; /* The value we are trying to push */
109  ballot sent_learn;
111 
112  struct {
113  ballot promise; /* Promise to not accept any proposals less than this */
114  pax_msg *msg; /* The value we have accepted */
116 
117  struct {
118  pax_msg *msg; /* The value we have learned */
120  int lock; /* Busy ? */
121  pax_op op;
123  int enforcer;
124 
125 #ifndef XCOM_STANDALONE
127 #endif
129 };
130 
132  synode_no synode);
135 pax_machine *get_cache_no_touch(synode_no synode, bool_t force);
136 pax_machine *get_cache(synode_no synode);
137 pax_machine *force_get_cache(synode_no synode);
138 pax_machine *hash_get(synode_no synode);
139 char *dbg_machine_nodeset(pax_machine *p, u_int nodes);
141 void init_cache();
142 void deinit_cache();
144 void xcom_cache_var_init();
145 size_t shrink_cache();
146 size_t pax_machine_size(pax_machine const *p);
147 synode_no cache_get_last_removed();
148 
149 void init_cache_size();
150 uint64_t add_cache_size(pax_machine *p);
151 uint64_t sub_cache_size(pax_machine *p);
152 int above_cache_limit();
153 uint64_t set_max_cache_size(uint64_t x);
154 int was_removed_from_cache(synode_no x);
155 uint16_t check_decrease();
156 void do_cache_maintenance();
157 
158 /* Unit testing */
159 #define DEC_THRESHOLD_LENGTH 500000 /* MIN_LENGTH * 10 */
160 #define MIN_TARGET_OCCUPATION 0.7F
161 #define DEC_THRESHOLD_SIZE 0.95F
162 #define MIN_LENGTH_THRESHOLD 0.9F
163 
164 uint64_t get_xcom_cache_occupation();
165 uint64_t get_xcom_cache_length();
166 uint64_t get_xcom_cache_size();
167 void set_length_increment(size_t increment);
168 void set_size_decrement(size_t decrement);
169 void set_dec_threshold_length(uint64_t threshold);
170 void set_min_target_occupation(float threshold);
171 void set_dec_threshold_size(float threshold);
172 void set_min_length_threshold(float threshold);
174 
175 #ifndef XCOM_STANDALONE
176 void psi_set_cache_resetting(int is_resetting);
178 void psi_report_mem_free(size_t size, int is_instrumented);
179 int psi_report_mem_alloc(size_t size);
180 #else
181 #define psi_set_cache_resetting(x) \
182  do { \
183  } while (0)
184 #define psi_report_cache_shutdown() \
185  do { \
186  } while (0)
187 #define psi_report_mem_free(x) \
188  do { \
189  } while (0)
190 #define psi_report_mem_alloc(x) \
191  do { \
192  } while (0)
193 #endif
194 
195 enum {
201  CACHE_INCREASING = 5
202 };
203 
204 #endif
const char * p
Definition: ctype-mb.cc:1236
required string event
Definition: replication_group_member_actions.proto:31
struct pax_msg pax_msg
Definition: site_struct.h:36
Definition: simset.h:35
Definition: xcom_cache.cc:61
Definition: xcom_cache.h:94
lru_machine * lru
Definition: xcom_cache.h:97
linkage rv
Definition: xcom_cache.h:100
bit_set * prep_nodeset
Definition: xcom_cache.h:105
paxos_fsm_state state
Definition: xcom_cache.h:128
struct pax_machine::@24 learner
int lock
Definition: xcom_cache.h:120
stack_machine * stack_link
Definition: xcom_cache.h:96
ballot bal
Definition: xcom_cache.h:104
synode_no synode
Definition: xcom_cache.h:98
struct pax_machine::@22 proposer
linkage hash_link
Definition: xcom_cache.h:95
ballot sent_learn
Definition: xcom_cache.h:109
bit_set * prop_nodeset
Definition: xcom_cache.h:107
char is_instrumented
Definition: xcom_cache.h:126
linkage watchdog
Definition: xcom_cache.h:101
ballot promise
Definition: xcom_cache.h:113
pax_op op
Definition: xcom_cache.h:121
ballot sent_prop
Definition: xcom_cache.h:106
int force_delivery
Definition: xcom_cache.h:122
struct pax_machine::@23 acceptor
double last_modified
Definition: xcom_cache.h:99
pax_msg * msg
Definition: xcom_cache.h:108
int enforcer
Definition: xcom_cache.h:123
Definition: xcom_cache.h:78
paxos_fsm_fp state_fp
Definition: xcom_cache.h:79
char const * state_name
Definition: xcom_cache.h:80
Definition: site_struct.h:42
Definition: xcom_cache.cc:89
__u_int u_int
Definition: types.h:72
int bool_t
Definition: types.h:34
uint64_t get_xcom_cache_occupation()
Definition: xcom_cache.cc:650
void psi_report_cache_shutdown()
After the cache is de-initialized 'current_count' must be zero; otherwise we have allocated data that...
Definition: gcs_psi.cc:219
int was_removed_from_cache(synode_no x)
Definition: xcom_cache.cc:70
paxos_event
Definition: xcom_cache.h:65
void set_dec_threshold_length(uint64_t threshold)
int paxos_fsm_idle(pax_machine *paxos, site_def const *site, paxos_event event, pax_msg *mess)
Definition: xcom_base.cc:8906
void paxos_timeout(pax_machine *p)
Definition: xcom_cache.cc:675
int psi_report_mem_alloc(size_t size)
Reports to PSI the allocation of 'size' bytes of data.
Definition: gcs_psi.cc:185
void psi_set_cache_resetting(int is_resetting)
pax_machine * force_get_cache(synode_no synode)
Definition: xcom_cache.cc:315
void set_size_decrement(size_t decrement)
Definition: xcom_cache.cc:656
char * dbg_pax_machine(pax_machine *p)
uint64_t sub_cache_size(pax_machine *p)
Definition: xcom_cache.cc:522
void set_min_target_occupation(float threshold)
Definition: xcom_cache.cc:664
void unlock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:429
pax_machine * get_cache_no_touch(synode_no synode, bool_t force)
Definition: xcom_cache.cc:296
void init_cache()
Definition: xcom_cache.cc:249
void set_dec_threshold_size(float threshold)
Definition: xcom_cache.cc:668
char * dbg_machine_nodeset(pax_machine *p, u_int nodes)
Definition: xcom_cache.cc:435
void set_length_increment(size_t increment)
Definition: xcom_cache.cc:654
synode_no cache_get_last_removed()
Definition: xcom_cache.cc:68
uint64_t add_cache_size(pax_machine *p)
Definition: xcom_cache.cc:508
void xcom_cache_var_init()
Definition: xcom_cache.cc:387
int(* paxos_fsm_fp)(pax_machine *paxos, site_def const *site, paxos_event event, pax_msg *mess)
Definition: xcom_cache.h:74
void psi_report_mem_free(size_t size, int is_instrumented)
Reports to PSI the deallocation of 'size' bytes of data.
Definition: gcs_psi.cc:203
pax_machine * init_pax_machine(pax_machine *p, lru_machine *lru, synode_no synode)
Definition: xcom_cache.cc:392
int lock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:423
@ CACHE_TOO_SMALL
Definition: xcom_cache.h:197
@ CACHE_RESULT_LOW
Definition: xcom_cache.h:200
@ CACHE_SHRINK_OK
Definition: xcom_cache.h:196
@ CACHE_INCREASING
Definition: xcom_cache.h:201
@ CACHE_HASH_NOTEMPTY
Definition: xcom_cache.h:198
@ CACHE_HIGH_OCCUPATION
Definition: xcom_cache.h:199
void deinit_cache()
Definition: xcom_cache.cc:277
uint16_t check_decrease()
Definition: xcom_cache.cc:601
uint64_t get_xcom_cache_size()
Definition: xcom_cache.cc:652
size_t shrink_cache()
Definition: xcom_cache.cc:368
uint64_t set_max_cache_size(uint64_t x)
Definition: xcom_cache.cc:542
void set_min_length_threshold(float threshold)
Definition: xcom_cache.cc:670
uint64_t get_xcom_cache_length()
Definition: xcom_cache.cc:651
pax_machine * get_cache(synode_no synode)
Definition: xcom_cache.cc:322
size_t pax_machine_size(pax_machine const *p)
Definition: xcom_cache.cc:489
pax_machine * hash_get(synode_no synode)
Definition: xcom_cache.cc:158
void do_cache_maintenance()
Definition: xcom_cache.cc:624
#define p_events
Definition: xcom_cache.h:59
void init_cache_size()
Definition: xcom_cache.cc:504
int is_busy_machine(pax_machine *p)
Definition: xcom_cache.cc:431
int above_cache_limit()
Definition: xcom_cache.cc:537