MySQL 9.0.0
Source Code Documentation
xcom_cache.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef XCOM_CACHE_H
25#define XCOM_CACHE_H
26
27#include <stddef.h>
28
29#include "xcom/simset.h"
30#include "xcom/site_struct.h"
31#include "xcom/xcom_profile.h"
32#include "xdr_gen/xcom_vp.h"
33
34/*
35We require that the number of elements in the cache is big enough enough that
36it is always possible to find instances that are not busy.
37Under normal circumstances the number of busy instances will be
38less than event_horizon, since the proposers only considers
39instances which belong to the local node.
40A node may start proposing no_ops for instances belonging
41to other nodes, meaning that event_horizon * NSERVERS instances may be
42involved. However, for the time being, proposing a no_op for an instance
43will not mark it as busy. This may change in the future, so a safe upper
44limit on the number of nodes marked as busy is event_horizon * NSERVERS.
45*/
46#define MIN_LENGTH MIN_CACHE_SIZE /* Also Default value */
47#define INCREMENT MIN_LENGTH /* Total number of slots to add/remove */
48
49#define is_cached(x) (hash_get(x) != NULL)
50
51struct lru_machine;
52typedef struct lru_machine lru_machine;
53
54struct stack_machine;
56
57struct pax_machine;
58typedef struct pax_machine pax_machine;
59
60#define p_events \
61 X(paxos_prepare), X(paxos_ack_prepare), X(paxos_accept), \
62 X(paxos_ack_accept), X(paxos_learn), X(paxos_start), X(paxos_tout), \
63 X(last_p_event)
64
65#define X(a) a
68#undef X
69
70struct paxos_fsm_state;
72
73/* Function pointer corresponding to a state. Return 1 if execution should
74 * continue, 0 otherwise */
75typedef int (*paxos_fsm_fp)(pax_machine *paxos, site_def const *site,
77
78/* Function pointer and name */
81 char const *state_name;
82};
83
84extern int paxos_fsm_idle(pax_machine *paxos, site_def const *site,
86
87// Set current Paxos state and name of state (for tracing) in pax_machine object
88#define SET_PAXOS_FSM_STATE(obj, s) \
89 do { \
90 (obj)->state.state_fp = s; \
91 (obj)->state.state_name = #s; \
92 } while (0)
93
94/* Definition of a Paxos instance */
99 synode_no synode;
100 double last_modified; /* Start time */
101 linkage rv; /* Tasks may sleep on this until something interesting happens */
102 linkage watchdog; /* Used for timeouts in Paxos */
103
104 struct {
105 ballot bal; /* The current ballot we are working on */
106 bit_set *prep_nodeset; /* Nodes which have answered my prepare */
107 ballot sent_prop;
108 bit_set *prop_nodeset; /* Nodes which have answered my propose */
109 pax_msg *msg; /* The value we are trying to push */
112
113 struct {
114 ballot promise; /* Promise to not accept any proposals less than this */
115 pax_msg *msg; /* The value we have accepted */
117
118 struct {
119 pax_msg *msg; /* The value we have learned */
121 int lock; /* Busy ? */
122 pax_op op;
125
126#ifndef XCOM_STANDALONE
128#endif
130};
131
133 synode_no synode);
136pax_machine *get_cache_no_touch(synode_no synode, bool_t force);
137pax_machine *get_cache(synode_no synode);
138pax_machine *force_get_cache(synode_no synode);
139pax_machine *hash_get(synode_no synode);
142void init_cache();
143void deinit_cache();
146size_t shrink_cache();
147size_t pax_machine_size(pax_machine const *p);
148synode_no cache_get_last_removed();
149
150void init_cache_size();
151uint64_t add_cache_size(pax_machine *p);
152uint64_t sub_cache_size(pax_machine *p);
154uint64_t set_max_cache_size(uint64_t x);
155int was_removed_from_cache(synode_no x);
156uint16_t check_decrease();
158
159/* Unit testing */
160#define DEC_THRESHOLD_LENGTH 500000 /* MIN_LENGTH * 10 */
161#define MIN_TARGET_OCCUPATION 0.7F
162#define DEC_THRESHOLD_SIZE 0.95F
163#define MIN_LENGTH_THRESHOLD 0.9F
164
166uint64_t get_xcom_cache_length();
167uint64_t get_xcom_cache_size();
168void set_length_increment(size_t increment);
169void set_size_decrement(size_t decrement);
170void set_dec_threshold_length(uint64_t threshold);
171void set_min_target_occupation(float threshold);
172void set_dec_threshold_size(float threshold);
173void set_min_length_threshold(float threshold);
175
176#ifndef XCOM_STANDALONE
177void psi_set_cache_resetting(int is_resetting);
179void psi_report_mem_free(size_t size, int is_instrumented);
180int psi_report_mem_alloc(size_t size);
181#else
182#define psi_set_cache_resetting(x) \
183 do { \
184 } while (0)
185#define psi_report_cache_shutdown() \
186 do { \
187 } while (0)
188#define psi_report_mem_free(x) \
189 do { \
190 } while (0)
191#define psi_report_mem_alloc(x) \
192 do { \
193 } while (0)
194#endif
195
196enum {
204
205#endif
const char * p
Definition: ctype-mb.cc:1225
size_t size(const char *const c)
Definition: base64.h:46
required string event
Definition: replication_group_member_actions.proto:32
struct pax_msg pax_msg
Definition: site_struct.h:37
Definition: simset.h:36
Definition: xcom_cache.cc:62
Definition: xcom_cache.h:95
lru_machine * lru
Definition: xcom_cache.h:98
linkage rv
Definition: xcom_cache.h:101
bit_set * prep_nodeset
Definition: xcom_cache.h:106
paxos_fsm_state state
Definition: xcom_cache.h:129
int lock
Definition: xcom_cache.h:121
struct pax_machine::@25 acceptor
stack_machine * stack_link
Definition: xcom_cache.h:97
ballot bal
Definition: xcom_cache.h:105
synode_no synode
Definition: xcom_cache.h:99
linkage hash_link
Definition: xcom_cache.h:96
ballot sent_learn
Definition: xcom_cache.h:110
bit_set * prop_nodeset
Definition: xcom_cache.h:108
char is_instrumented
Definition: xcom_cache.h:127
linkage watchdog
Definition: xcom_cache.h:102
ballot promise
Definition: xcom_cache.h:114
pax_op op
Definition: xcom_cache.h:122
ballot sent_prop
Definition: xcom_cache.h:107
int force_delivery
Definition: xcom_cache.h:123
struct pax_machine::@24 proposer
double last_modified
Definition: xcom_cache.h:100
pax_msg * msg
Definition: xcom_cache.h:109
struct pax_machine::@26 learner
int enforcer
Definition: xcom_cache.h:124
Definition: xcom_cache.h:79
paxos_fsm_fp state_fp
Definition: xcom_cache.h:80
char const * state_name
Definition: xcom_cache.h:81
Definition: site_struct.h:43
Definition: xcom_cache.cc:90
__u_int u_int
Definition: types.h:73
int bool_t
Definition: types.h:35
uint64_t get_xcom_cache_occupation()
Definition: xcom_cache.cc:654
pax_machine * init_pax_machine(pax_machine *p, lru_machine *lru, synode_no synode)
Definition: xcom_cache.cc:394
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:222
int was_removed_from_cache(synode_no x)
Definition: xcom_cache.cc:71
paxos_event
Definition: xcom_cache.h:66
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:9058
void paxos_timeout(pax_machine *p)
Definition: xcom_cache.cc:679
pax_machine * get_cache_no_touch(synode_no synode, bool_t force)
Definition: xcom_cache.cc:297
int psi_report_mem_alloc(size_t size)
Reports to PSI the allocation of 'size' bytes of data.
Definition: gcs_psi.cc:190
void psi_set_cache_resetting(int is_resetting)
void set_size_decrement(size_t decrement)
Definition: xcom_cache.cc:660
uint64_t sub_cache_size(pax_machine *p)
Definition: xcom_cache.cc:524
void set_min_target_occupation(float threshold)
Definition: xcom_cache.cc:668
void unlock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:431
void init_cache()
Definition: xcom_cache.cc:250
void set_dec_threshold_size(float threshold)
Definition: xcom_cache.cc:672
pax_machine * force_get_cache(synode_no synode)
Definition: xcom_cache.cc:316
void set_length_increment(size_t increment)
Definition: xcom_cache.cc:658
synode_no cache_get_last_removed()
Definition: xcom_cache.cc:69
uint64_t add_cache_size(pax_machine *p)
Definition: xcom_cache.cc:510
void xcom_cache_var_init()
Definition: xcom_cache.cc:389
int(* paxos_fsm_fp)(pax_machine *paxos, site_def const *site, paxos_event event, pax_msg *mess)
Definition: xcom_cache.h:75
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:206
pax_machine * get_cache(synode_no synode)
Definition: xcom_cache.cc:323
int lock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:425
pax_machine * hash_get(synode_no synode)
Definition: xcom_cache.cc:159
void deinit_cache()
Definition: xcom_cache.cc:278
@ CACHE_TOO_SMALL
Definition: xcom_cache.h:198
@ CACHE_RESULT_LOW
Definition: xcom_cache.h:201
@ CACHE_SHRINK_OK
Definition: xcom_cache.h:197
@ CACHE_INCREASING
Definition: xcom_cache.h:202
@ CACHE_HASH_NOTEMPTY
Definition: xcom_cache.h:199
@ CACHE_HIGH_OCCUPATION
Definition: xcom_cache.h:200
uint16_t check_decrease()
Definition: xcom_cache.cc:603
uint64_t get_xcom_cache_size()
Definition: xcom_cache.cc:656
size_t shrink_cache()
Definition: xcom_cache.cc:370
uint64_t set_max_cache_size(uint64_t x)
Definition: xcom_cache.cc:544
void set_min_length_threshold(float threshold)
Definition: xcom_cache.cc:674
uint64_t get_xcom_cache_length()
Definition: xcom_cache.cc:655
char * dbg_pax_machine(pax_machine *p)
char * dbg_machine_nodeset(pax_machine *p, u_int nodes)
Definition: xcom_cache.cc:437
size_t pax_machine_size(pax_machine const *p)
Definition: xcom_cache.cc:491
void do_cache_maintenance()
Definition: xcom_cache.cc:626
#define p_events
Definition: xcom_cache.h:60
void init_cache_size()
Definition: xcom_cache.cc:506
int is_busy_machine(pax_machine *p)
Definition: xcom_cache.cc:433
int above_cache_limit()
Definition: xcom_cache.cc:539