MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NdbPoolImpl.hpp
1 /*
2  Copyright (C) 2003, 2005, 2006 MySQL AB
3  All rights reserved. Use is subject to license terms.
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; version 2 of the License.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18 
74 #ifndef NdbPool_H
75 #define NdbPool_H
76 
77 #include <Ndb.hpp>
78 #include <NdbMutex.h>
79 #include <NdbCondition.h>
80 #include <NdbOut.hpp>
81 
82 class NdbPool {
83 #define NULL_POOL 0
84 #define NULL_HASH 0xFF
85 #define POOL_HASH_TABLE_SIZE 32
86 #define MAX_NDB_OBJECTS 240
87  struct POOL_STRUCT {
88  Ndb* ndb_reference;
89  bool in_use;
90  bool free_entry;
91  Uint16 next_free_object;
92  Uint16 prev_free_object;
93  Uint16 next_db_object;
94  Uint16 prev_db_object;
95  };
96  public:
97  static NdbPool* create_instance(Ndb_cluster_connection*,
98  Uint32 max_ndb_objects = 240,
99  Uint32 no_conn_obj = 4,
100  Uint32 init_no_ndb_objects = 8);
101  static void drop_instance();
102  Ndb* get_ndb_object(Uint32 &hint_id,
103  const char* a_catalog_name,
104  const char* a_schema_name);
105  void return_ndb_object(Ndb* returned_object, Uint32 id);
106  private:
107  bool init(Uint32 initial_no_of_ndb_objects = 8);
108  void release_all();
109  static bool initPoolMutex();
111  Uint32 max_no_of_ndb_objects, Uint32 no_conn_objects);
112  ~NdbPool();
113  /*
114  We have three lists:
115  1) A list for entries not in use
116  2) A list for free entries
117  3) A hash table with schema name and database name as key
118 
119  These lists are all initialised in the init call.
120  The list for entries not in use is very simple since the current
121  implementation have not yet any handling of dropping Ndb objects
122  until all Ndb objects are dropped.
123  */
124  void add_free_list(Uint32 id);
125  void remove_free_list(Uint32 id);
126  Ndb* get_free_list(Uint32 &id, Uint32 hash_entry);
127 
128  void add_db_hash(Uint32 id);
129  void remove_db_hash(Uint32 id, Uint32 hash_entry);
130  Ndb* get_db_hash(Uint32 &id,
131  Uint32 hash_entry,
132  const char* a_catalog_name,
133  const char* a_schema_name);
134 
135  bool allocate_ndb(Uint32 &id,
136  const char* a_catalog_name,
137  const char* a_schema_name);
138  Ndb* get_hint_ndb(Uint32 id, Uint32 hash_entry);
139  Ndb* wait_free_ndb(Uint32 &id);
140  Uint32 compute_hash(const char *a_schema_name);
141  void add_wait_list(Uint32 id);
142  void remove_wait_list();
143  void switch_condition_queue();
144 
145  static NdbMutex *pool_mutex;
146  struct NdbCondition *input_pool_cond;
147  struct NdbCondition *output_pool_cond;
148 
149  POOL_STRUCT *m_pool_reference;
150  Uint8 *m_hash_entry;
151 
152  bool m_inited;
153  Uint32 m_no_of_conn_objects;
154 
155  Uint16 m_no_of_objects;
156  Uint16 m_max_ndb_objects;
157  Uint16 m_first_free;
158  Uint16 m_last_free;
159  Uint16 m_first_not_in_use;
160  Uint16 m_waiting;
161  Uint16 m_first_wait;
162  Uint16 m_input_queue;
163  Uint16 m_output_queue;
164  Uint16 m_signal_count;
165 
166  Ndb_cluster_connection * m_cluster_connection;
167 };
168 #endif