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 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 /* 31 We require that the number of elements in the cache is big enough enough that 32 it is always possible to find instances that are not busy. 33 Under normal circumstances the number of busy instances will be 34 less than event_horizon, since the proposers only considers 35 instances which belong to the local node. 36 A node may start proposing no_ops for instances belonging 37 to other nodes, meaning that event_horizon * NSERVERS instances may be 38 involved. However, for the time being, proposing a no_op for an instance 39 will not mark it as busy. This may change in the future, so a safe upper 40 limit on the number of nodes marked as busy is event_horizon * NSERVERS. 41 */ 42 #define CACHED 50000 43 44 #define is_cached(x) (hash_get(x) != NULL) 45 46 struct lru_machine ; 47 typedef struct lru_machine lru_machine; 48 49 struct pax_machine ; 50 typedef struct pax_machine pax_machine; 51 52 /* Definition of a Paxos instance */ 53 struct pax_machine { 54 linkage hash_link; 55 lru_machine * lru; 56 synode_no synode; 57 double last_modified; /* Start time */ 58 linkage rv; /* Tasks may sleep on this until something interesting happens */ 59 60 struct { 61 ballot bal; /* The current ballot we are working on */ 62 bit_set * prep_nodeset; /* Nodes which have answered my prepare */ 63 ballot sent_prop; 64 bit_set * prop_nodeset; /* Nodes which have answered my propose */ 65 pax_msg * msg; /* The value we are trying to push */ 66 ballot sent_learn; 67 } proposer; 68 69 struct { 70 ballot promise; /* Promise to not accept any proposals less than this */ 71 pax_msg * msg; /* The value we have accepted */ 72 } acceptor; 73 74 struct { 75 pax_msg *msg; /* The value we have learned */ 76 } learner; 77 int lock; /* Busy ? */ 78 pax_op op; 79 int force_delivery; 80 }; 81 82 83 int is_busy_machine(pax_machine *p); 84 int lock_pax_machine(pax_machine *p); 85 pax_machine *get_cache_no_touch(synode_no synode); 86 pax_machine *get_cache(synode_no synode); 87 pax_machine *hash_get(synode_no synode); 88 char *dbg_machine_nodeset(pax_machine *p, u_int nodes); 89 char *dbg_pax_machine(pax_machine *p); 90 void init_cache(); 91 void deinit_cache(); 92 void unlock_pax_machine(pax_machine *p); 93 void xcom_cache_var_init(); 94 void shrink_cache(); 95 size_t pax_machine_size(pax_machine const *p); 96 97 void init_cache_size(); 98 size_t add_cache_size(size_t x); 99 size_t sub_cache_size(size_t x); 100 int above_cache_limit(); 101 size_t set_max_cache_size(size_t x); 102 int was_removed_from_cache(synode_no x); 103 104 #ifdef __cplusplus 105 } 106 #endif 107 108 #endif 109 110