1 /* Copyright (c) 2003-2008 MySQL AB
2    Use is subject to license terms
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 Street, Fifth Floor, Boston, MA  02110-1301, USA */
16 
17 #ifndef DictCache_H
18 #define DictCache_H
19 
20 #include <ndb_types.h>
21 #include <kernel_types.h>
22 #include <NdbError.hpp>
23 #include <BaseString.hpp>
24 #include <Vector.hpp>
25 #include <UtilBuffer.hpp>
26 #include <NdbDictionary.hpp>
27 #include <Ndb.hpp>
28 #include <NdbCondition.h>
29 #include "NdbLinHash.hpp"
30 
31 class Ndb_local_table_info {
32 public:
33   static Ndb_local_table_info *create(NdbTableImpl *table_impl, Uint32 sz=0);
34   static void destroy(Ndb_local_table_info *);
35   NdbTableImpl *m_table_impl;
36 
37   // range of cached tuple ids per thread
38   Ndb::TupleIdRange m_tuple_id_range;
39 
40   Uint64 m_local_data[1]; // Must be last member. Used to access extra space.
41 private:
42   Ndb_local_table_info(NdbTableImpl *table_impl);
43   ~Ndb_local_table_info();
44 };
45 
46 /**
47  * A non thread safe dict cache
48  */
49 class LocalDictCache {
50 public:
51   LocalDictCache();
52   ~LocalDictCache();
53 
54   Ndb_local_table_info * get(const char * name);
55 
56   void put(const char * name, Ndb_local_table_info *);
57   void drop(const char * name);
58 
59   NdbLinHash<Ndb_local_table_info> m_tableHash; // On name
60 };
61 
62 /**
63  * A thread safe dict cache
64  */
65 class GlobalDictCache : public NdbLockable {
66 public:
67   GlobalDictCache();
68   ~GlobalDictCache();
69 
70   NdbTableImpl * get(NdbTableImpl *tab);
71   NdbTableImpl * get(const char * name, int *error);
72 
73   NdbTableImpl* put(const char * name, NdbTableImpl *);
74   void release(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 public:
82   enum Status {
83     OK = 0,
84     DROPPED = 1,
85     RETREIVING = 2
86   };
87 
88 private:
89   void printCache();
90 
91   struct TableVersion {
92     Uint32 m_version;
93     Uint32 m_refCount;
94     NdbTableImpl * m_impl;
95     Status m_status;
96   };
97 
98   NdbLinHash<Vector<TableVersion> > m_tableHash;
99   NdbCondition * m_waitForTableCondition;
100 };
101 
102 #endif
103 
104 
105