MySQL  8.0.20
Source Code Documentation
xcom_cache.h
Go to the documentation of this file.
1 /* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
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 
29 #include "plugin/group_replication/libmysqlgcs/xdr_gen/xcom_vp.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36 We require that the number of elements in the cache is big enough enough that
37 it is always possible to find instances that are not busy.
38 Under normal circumstances the number of busy instances will be
39 less than event_horizon, since the proposers only considers
40 instances which belong to the local node.
41 A node may start proposing no_ops for instances belonging
42 to other nodes, meaning that event_horizon * NSERVERS instances may be
43 involved. However, for the time being, proposing a no_op for an instance
44 will not mark it as busy. This may change in the future, so a safe upper
45 limit on the number of nodes marked as busy is event_horizon * NSERVERS.
46 */
47 #define MIN_LENGTH 250000 // Also Default value
48 #define INCREMENT MIN_LENGTH // Total number of slots to add/remove
49 
50 #define is_cached(x) (hash_get(x) != NULL)
51 
52 struct lru_machine;
53 typedef struct lru_machine lru_machine;
54 
55 struct stack_machine;
57 
58 struct pax_machine;
59 typedef struct pax_machine pax_machine;
60 
61 /* Definition of a Paxos instance */
62 struct pax_machine {
66  synode_no synode;
67  double last_modified; /* Start time */
68  linkage rv; /* Tasks may sleep on this until something interesting happens */
69 
70  struct {
71  ballot bal; /* The current ballot we are working on */
72  bit_set *prep_nodeset; /* Nodes which have answered my prepare */
73  ballot sent_prop;
74  bit_set *prop_nodeset; /* Nodes which have answered my propose */
75  pax_msg *msg; /* The value we are trying to push */
76  ballot sent_learn;
77  } proposer;
78 
79  struct {
80  ballot promise; /* Promise to not accept any proposals less than this */
81  pax_msg *msg; /* The value we have accepted */
82  } acceptor;
83 
84  struct {
85  pax_msg *msg; /* The value we have learned */
86  } learner;
87  int lock; /* Busy ? */
88  pax_op op;
90  int enforcer;
91 
92 #ifndef XCOM_STANDALONE
94 #endif
95 };
96 
98  synode_no synode);
101 pax_machine *get_cache_no_touch(synode_no synode, bool_t force);
102 pax_machine *get_cache(synode_no synode);
104 pax_machine *hash_get(synode_no synode);
105 char *dbg_machine_nodeset(pax_machine *p, u_int nodes);
107 void init_cache();
108 void deinit_cache();
110 void xcom_cache_var_init();
111 size_t shrink_cache();
112 size_t pax_machine_size(pax_machine const *p);
113 synode_no cache_get_last_removed();
114 
115 void init_cache_size();
116 size_t add_cache_size(pax_machine *p);
117 size_t sub_cache_size(pax_machine *p);
118 int above_cache_limit();
119 size_t set_max_cache_size(uint64_t x);
120 int was_removed_from_cache(synode_no x);
121 uint16_t check_decrease();
122 void do_cache_maintenance();
123 
124 // Unit testing
125 #define DEC_THRESHOLD_LENGTH 500000 // MIN_LENGTH * 10
126 #define MIN_TARGET_OCCUPATION 0.7
127 #define DEC_THRESHOLD_SIZE 0.95
128 #define MIN_LENGTH_THRESHOLD 0.9
129 
130 uint64_t get_xcom_cache_occupation();
131 uint64_t get_xcom_cache_length();
132 uint64_t get_xcom_cache_size();
133 void set_length_increment(size_t increment);
134 void set_size_decrement(size_t decrement);
135 void set_dec_threshold_length(uint64_t threshold);
136 void set_min_target_occupation(float threshold);
137 void set_dec_threshold_size(float threshold);
138 void set_min_length_threshold(float threshold);
139 
140 #ifndef XCOM_STANDALONE
141 void psi_set_cache_resetting(int is_resetting);
143 void psi_report_mem_free(size_t size, int is_instrumented);
144 int psi_report_mem_alloc(size_t size);
145 #else
146 #define psi_set_cache_resetting(x) \
147  do { \
148  } while (0)
149 #define psi_report_cache_shutdown(x) \
150  do { \
151  } while (0)
152 #define psi_report_mem_free(x) \
153  do { \
154  } while (0)
155 #define psi_report_mem_alloc(x) \
156  do { \
157  } while (0)
158 #endif
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif
pax_machine * get_cache(synode_no synode)
Definition: xcom_cache.c:353
int lock_pax_machine(pax_machine *p)
Definition: xcom_cache.c:454
pax_machine * get_cache_no_touch(synode_no synode, bool_t force)
Definition: xcom_cache.c:327
void deinit_cache()
Definition: xcom_cache.c:308
pax_op op
Definition: xcom_cache.h:88
double last_modified
Definition: xcom_cache.h:67
pax_machine * hash_get(synode_no synode)
Definition: xcom_cache.c:178
ballot sent_learn
Definition: xcom_cache.h:76
struct pax_machine::@17 learner
int enforcer
Definition: xcom_cache.h:90
ballot promise
Definition: xcom_cache.h:80
ballot bal
Definition: xcom_cache.h:71
Definition: xcom_cache.c:84
size_t sub_cache_size(pax_machine *p)
Definition: xcom_cache.c:551
Definition: xcom_cache.c:57
struct pax_machine::@15 proposer
linkage rv
Definition: xcom_cache.h:68
size_t shrink_cache()
Definition: xcom_cache.c:399
pax_machine * init_pax_machine(pax_machine *p, lru_machine *lru, synode_no synode)
Definition: xcom_cache.c:425
void init_cache_size()
Definition: xcom_cache.c:533
uint64_t get_xcom_cache_length()
Definition: xcom_cache.c:669
stack_machine * stack_link
Definition: xcom_cache.h:64
void set_dec_threshold_size(float threshold)
Definition: xcom_cache.c:684
void set_size_decrement(size_t decrement)
Definition: xcom_cache.c:674
pax_machine * force_get_cache(synode_no synode)
Definition: xcom_cache.c:346
void do_cache_maintenance()
Definition: xcom_cache.c:643
int is_busy_machine(pax_machine *p)
Definition: xcom_cache.c:462
void init_cache()
Definition: xcom_cache.c:281
void xcom_cache_var_init()
Definition: xcom_cache.c:418
Definition: simset.h:39
char * dbg_pax_machine(pax_machine *p)
Definition: xcom_cache.c:476
void set_length_increment(size_t increment)
Definition: xcom_cache.c:672
int psi_report_mem_alloc(size_t size)
Reports to PSI the allocation of &#39;size&#39; bytes of data.
Definition: gcs_psi.cc:182
pax_msg * msg
Definition: xcom_cache.h:75
void set_dec_threshold_length(uint64_t threshold)
Definition: xcom_cache.c:676
ballot sent_prop
Definition: xcom_cache.h:73
struct pax_machine::@16 acceptor
int was_removed_from_cache(synode_no x)
Definition: xcom_cache.c:66
synode_no cache_get_last_removed()
Definition: xcom_cache.c:64
char * dbg_machine_nodeset(pax_machine *p, u_int nodes)
Definition: xcom_cache.c:466
void psi_report_cache_shutdown()
After the cache is de-initialized &#39;current_count&#39; must be zero; otherwise we have allocated data that...
Definition: gcs_psi.cc:216
void psi_set_cache_resetting(int is_resetting)
__u_int u_int
Definition: types.h:73
linkage hash_link
Definition: xcom_cache.h:63
int bool_t
Definition: types.h:35
uint64_t get_xcom_cache_occupation()
Definition: xcom_cache.c:668
void set_min_target_occupation(float threshold)
Definition: xcom_cache.c:680
size_t set_max_cache_size(uint64_t x)
Definition: xcom_cache.c:571
int above_cache_limit()
Definition: xcom_cache.c:566
Definition: xcom_cache.h:62
char is_instrumented
Definition: xcom_cache.h:93
uint64_t get_xcom_cache_size()
Definition: xcom_cache.c:670
uint16_t check_decrease()
Definition: xcom_cache.c:625
size_t pax_machine_size(pax_machine const *p)
Definition: xcom_cache.c:518
bit_set * prop_nodeset
Definition: xcom_cache.h:74
synode_no synode
Definition: xcom_cache.h:66
int lock
Definition: xcom_cache.h:87
const char * p
Definition: ctype-mb.cc:1235
void psi_report_mem_free(size_t size, int is_instrumented)
Reports to PSI the deallocation of &#39;size&#39; bytes of data.
Definition: gcs_psi.cc:200
int force_delivery
Definition: xcom_cache.h:89
lru_machine * lru
Definition: xcom_cache.h:65
bit_set * prep_nodeset
Definition: xcom_cache.h:72
void set_min_length_threshold(float threshold)
Definition: xcom_cache.c:686
void unlock_pax_machine(pax_machine *p)
Definition: xcom_cache.c:460
size_t add_cache_size(pax_machine *p)
Definition: xcom_cache.c:537