1 /* 2 Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 3 4 This program is free software; you can redistribute it and/or modify 5 it under the terms of the GNU General Public License, version 2.0, 6 as published by the Free Software Foundation. 7 8 This program is also distributed with certain software (including 9 but not limited to OpenSSL) that is licensed under separate terms, 10 as designated in a particular file or component or in included license 11 documentation. The authors of MySQL hereby grant you an additional 12 permission to link the program and your derivative works with the 13 separately licensed software that they have included with MySQL. 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 25 #ifndef DictCache_H 26 #define DictCache_H 27 28 #include <ndb_types.h> 29 #include <kernel_types.h> 30 #include <NdbError.hpp> 31 #include <BaseString.hpp> 32 #include <Vector.hpp> 33 #include <UtilBuffer.hpp> 34 #include <NdbDictionary.hpp> 35 #include <Ndb.hpp> 36 #include <NdbCondition.h> 37 #include "NdbLinHash.hpp" 38 39 class Ndb_local_table_info { 40 public: 41 static Ndb_local_table_info *create(NdbTableImpl *table_impl, Uint32 sz=0); 42 static void destroy(Ndb_local_table_info *); 43 NdbTableImpl *m_table_impl; 44 45 // range of cached tuple ids per thread 46 Ndb::TupleIdRange m_tuple_id_range; 47 48 Uint64 m_local_data[1]; // Must be last member. Used to access extra space. 49 private: 50 Ndb_local_table_info(NdbTableImpl *table_impl); 51 ~Ndb_local_table_info(); 52 }; 53 54 /** 55 * A non thread safe dict cache 56 */ 57 class LocalDictCache { 58 public: 59 LocalDictCache(); 60 ~LocalDictCache(); 61 62 Ndb_local_table_info * get(const char * name); 63 64 void put(const char * name, Ndb_local_table_info *); 65 void drop(const char * name); 66 67 NdbLinHash<Ndb_local_table_info> m_tableHash; // On name 68 }; 69 70 /** 71 * A thread safe dict cache 72 */ 73 class GlobalDictCache : public NdbLockable { 74 public: 75 GlobalDictCache(); 76 ~GlobalDictCache(); 77 78 NdbTableImpl * get(const char * name, int *error); 79 80 NdbTableImpl* put(const char * name, NdbTableImpl *); 81 void release(const NdbTableImpl *, int invalidate = 0); 82 83 void alter_table_rep(const char * name, 84 Uint32 tableId, Uint32 tableVersion, bool altered); 85 86 unsigned get_size(); 87 void invalidate_all(); 88 89 // update reference count by +1 or -1 inc_ref_count(const NdbTableImpl * impl)90 int inc_ref_count(const NdbTableImpl * impl) { 91 return chg_ref_count(impl, +1); 92 } dec_ref_count(const NdbTableImpl * impl)93 int dec_ref_count(const NdbTableImpl * impl) { 94 return chg_ref_count(impl, -1); 95 } 96 97 void invalidateDb(const char * name, size_t len); 98 99 public: 100 enum Status { 101 OK = 0, 102 DROPPED = 1, 103 RETREIVING = 2 104 }; 105 106 private: 107 void printCache(); 108 int chg_ref_count(const NdbTableImpl *, int value); 109 110 struct TableVersion { 111 Uint32 m_version; 112 Uint32 m_refCount; 113 NdbTableImpl * m_impl; 114 Status m_status; 115 }; 116 117 NdbLinHash<Vector<TableVersion> > m_tableHash; 118 NdbCondition * m_waitForTableCondition; 119 }; 120 121 #endif 122 123 124