MySQL 8.3.0
Source Code Documentation
xcom_cache.h
Go to the documentation of this file.
1/* Copyright (c) 2015, 2023, 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/*
34We require that the number of elements in the cache is big enough enough that
35it is always possible to find instances that are not busy.
36Under normal circumstances the number of busy instances will be
37less than event_horizon, since the proposers only considers
38instances which belong to the local node.
39A node may start proposing no_ops for instances belonging
40to other nodes, meaning that event_horizon * NSERVERS instances may be
41involved. However, for the time being, proposing a no_op for an instance
42will not mark it as busy. This may change in the future, so a safe upper
43limit 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
50struct lru_machine;
51typedef struct lru_machine lru_machine;
52
53struct stack_machine;
55
56struct pax_machine;
57typedef 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
67#undef X
68
69struct paxos_fsm_state;
71
72/* Function pointer corresponding to a state. Return 1 if execution should
73 * continue, 0 otherwise */
74typedef int (*paxos_fsm_fp)(pax_machine *paxos, site_def const *site,
76
77/* Function pointer and name */
80 char const *state_name;
81};
82
83extern int paxos_fsm_idle(pax_machine *paxos, site_def const *site,
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 */
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 */
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;
124
125#ifndef XCOM_STANDALONE
127#endif
129};
130
132 synode_no synode);
135pax_machine *get_cache_no_touch(synode_no synode, bool_t force);
136pax_machine *get_cache(synode_no synode);
137pax_machine *force_get_cache(synode_no synode);
138pax_machine *hash_get(synode_no synode);
141void init_cache();
142void deinit_cache();
145size_t shrink_cache();
146size_t pax_machine_size(pax_machine const *p);
147synode_no cache_get_last_removed();
148
149void init_cache_size();
150uint64_t add_cache_size(pax_machine *p);
151uint64_t sub_cache_size(pax_machine *p);
153uint64_t set_max_cache_size(uint64_t x);
154int was_removed_from_cache(synode_no x);
155uint16_t check_decrease();
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
165uint64_t get_xcom_cache_length();
166uint64_t get_xcom_cache_size();
167void set_length_increment(size_t increment);
168void set_size_decrement(size_t decrement);
169void set_dec_threshold_length(uint64_t threshold);
170void set_min_target_occupation(float threshold);
171void set_dec_threshold_size(float threshold);
172void set_min_length_threshold(float threshold);
174
175#ifndef XCOM_STANDALONE
176void psi_set_cache_resetting(int is_resetting);
178void psi_report_mem_free(size_t size, int is_instrumented);
179int 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
195enum {
203
204#endif
const char * p
Definition: ctype-mb.cc:1234
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
int lock
Definition: xcom_cache.h:120
struct pax_machine::@25 acceptor
stack_machine * stack_link
Definition: xcom_cache.h:96
ballot bal
Definition: xcom_cache.h:104
synode_no synode
Definition: xcom_cache.h:98
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::@24 proposer
double last_modified
Definition: xcom_cache.h:99
pax_msg * msg
Definition: xcom_cache.h:108
struct pax_machine::@26 learner
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:653
pax_machine * init_pax_machine(pax_machine *p, lru_machine *lru, synode_no synode)
Definition: xcom_cache.cc:393
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:221
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:9057
void paxos_timeout(pax_machine *p)
Definition: xcom_cache.cc:678
pax_machine * get_cache_no_touch(synode_no synode, bool_t force)
Definition: xcom_cache.cc:296
int psi_report_mem_alloc(size_t size)
Reports to PSI the allocation of 'size' bytes of data.
Definition: gcs_psi.cc:189
void psi_set_cache_resetting(int is_resetting)
void set_size_decrement(size_t decrement)
Definition: xcom_cache.cc:659
uint64_t sub_cache_size(pax_machine *p)
Definition: xcom_cache.cc:523
void set_min_target_occupation(float threshold)
Definition: xcom_cache.cc:667
void unlock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:430
void init_cache()
Definition: xcom_cache.cc:249
void set_dec_threshold_size(float threshold)
Definition: xcom_cache.cc:671
pax_machine * force_get_cache(synode_no synode)
Definition: xcom_cache.cc:315
void set_length_increment(size_t increment)
Definition: xcom_cache.cc:657
synode_no cache_get_last_removed()
Definition: xcom_cache.cc:68
uint64_t add_cache_size(pax_machine *p)
Definition: xcom_cache.cc:509
void xcom_cache_var_init()
Definition: xcom_cache.cc:388
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:205
pax_machine * get_cache(synode_no synode)
Definition: xcom_cache.cc:322
int lock_pax_machine(pax_machine *p)
Definition: xcom_cache.cc:424
pax_machine * hash_get(synode_no synode)
Definition: xcom_cache.cc:158
void deinit_cache()
Definition: xcom_cache.cc:277
@ 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
uint16_t check_decrease()
Definition: xcom_cache.cc:602
uint64_t get_xcom_cache_size()
Definition: xcom_cache.cc:655
size_t shrink_cache()
Definition: xcom_cache.cc:369
uint64_t set_max_cache_size(uint64_t x)
Definition: xcom_cache.cc:543
void set_min_length_threshold(float threshold)
Definition: xcom_cache.cc:673
uint64_t get_xcom_cache_length()
Definition: xcom_cache.cc:654
char * dbg_pax_machine(pax_machine *p)
char * dbg_machine_nodeset(pax_machine *p, u_int nodes)
Definition: xcom_cache.cc:436
size_t pax_machine_size(pax_machine const *p)
Definition: xcom_cache.cc:490
void do_cache_maintenance()
Definition: xcom_cache.cc:625
#define p_events
Definition: xcom_cache.h:59
void init_cache_size()
Definition: xcom_cache.cc:505
int is_busy_machine(pax_machine *p)
Definition: xcom_cache.cc:432
int above_cache_limit()
Definition: xcom_cache.cc:538