MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DictCache.hpp
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 as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef DictCache_H
19 #define DictCache_H
20 
21 #include <ndb_types.h>
22 #include <kernel_types.h>
23 #include <NdbError.hpp>
24 #include <BaseString.hpp>
25 #include <Vector.hpp>
26 #include <UtilBuffer.hpp>
27 #include <NdbDictionary.hpp>
28 #include <Ndb.hpp>
29 #include <NdbCondition.h>
30 #include "NdbLinHash.hpp"
31 
33 public:
34  static Ndb_local_table_info *create(NdbTableImpl *table_impl, Uint32 sz=0);
35  static void destroy(Ndb_local_table_info *);
36  NdbTableImpl *m_table_impl;
37 
38  // range of cached tuple ids per thread
39  Ndb::TupleIdRange m_tuple_id_range;
40 
41  Uint64 m_local_data[1]; // Must be last member. Used to access extra space.
42 private:
45 };
46 
51 public:
53  ~LocalDictCache();
54 
55  Ndb_local_table_info * get(const char * name);
56 
57  void put(const char * name, Ndb_local_table_info *);
58  void drop(const char * name);
59 
60  NdbLinHash<Ndb_local_table_info> m_tableHash; // On name
61 };
62 
66 class GlobalDictCache : public NdbLockable {
67 public:
69  ~GlobalDictCache();
70 
71  NdbTableImpl * get(const char * name, int *error);
72 
73  NdbTableImpl* put(const char * name, NdbTableImpl *);
74  void release(const NdbTableImpl *, int invalidate = 0);
75 
76  void alter_table_rep(const char * name,
77  Uint32 tableId, Uint32 tableVersion, bool altered);
78 
79  unsigned get_size();
80  void invalidate_all();
81 
82  // update reference count by +1 or -1
83  int inc_ref_count(const NdbTableImpl * impl) {
84  return chg_ref_count(impl, +1);
85  }
86  int dec_ref_count(const NdbTableImpl * impl) {
87  return chg_ref_count(impl, -1);
88  }
89 
90  void invalidateDb(const char * name, size_t len);
91 
92 public:
93  enum Status {
94  OK = 0,
95  DROPPED = 1,
96  RETREIVING = 2
97  };
98 
99 private:
100  void printCache();
101  int chg_ref_count(const NdbTableImpl *, int value);
102 
103  struct TableVersion {
104  Uint32 m_version;
105  Uint32 m_refCount;
106  NdbTableImpl * m_impl;
107  Status m_status;
108  };
109 
110  NdbLinHash<Vector<TableVersion> > m_tableHash;
111  NdbCondition * m_waitForTableCondition;
112 };
113 
114 #endif
115 
116