~ubuntu-branches/ubuntu/precise/mysql-5.5/precise-201203300109

« back to all changes in this revision

Viewing changes to storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2011-11-08 11:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20111108113113-3ulw01fvi4vn8m25
Tags: upstream-5.5.17
ImportĀ upstreamĀ versionĀ 5.5.17

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
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 as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef NdbDictionaryImpl_H
 
17
#define NdbDictionaryImpl_H
 
18
 
 
19
#include <ndb_types.h>
 
20
#include <kernel_types.h>
 
21
#include <NdbError.hpp>
 
22
#include <BaseString.hpp>
 
23
#include <Vector.hpp>
 
24
#include <UtilBuffer.hpp>
 
25
#include <NdbDictionary.hpp>
 
26
#include <Bitmask.hpp>
 
27
#include <AttributeList.hpp>
 
28
#include <Ndb.hpp>
 
29
#include "NdbWaiter.hpp"
 
30
#include "DictCache.hpp"
 
31
 
 
32
bool
 
33
is_ndb_blob_table(const char* name, Uint32* ptab_id = 0, Uint32* pcol_no = 0);
 
34
bool
 
35
is_ndb_blob_table(const class NdbTableImpl* t);
 
36
 
 
37
extern int ndb_dictionary_is_mysqld;
 
38
#define ASSERT_NOT_MYSQLD assert(ndb_dictionary_is_mysqld == 0)
 
39
 
 
40
class NdbDictObjectImpl {
 
41
public:
 
42
  int m_id;
 
43
  Uint32 m_version;
 
44
  NdbDictionary::Object::Type m_type;
 
45
  NdbDictionary::Object::Status m_status;
 
46
  
 
47
  bool change();
 
48
  
 
49
  static NdbDictObjectImpl & getImpl(NdbDictionary::ObjectId & t) { 
 
50
    return t.m_impl;
 
51
  }
 
52
  static const NdbDictObjectImpl & getImpl(const NdbDictionary::ObjectId & t){
 
53
    return t.m_impl;
 
54
  }
 
55
  
 
56
protected:
 
57
  friend class NdbDictionary::ObjectId;
 
58
 
 
59
  NdbDictObjectImpl(NdbDictionary::Object::Type type) :
 
60
    m_type(type),
 
61
    m_status(NdbDictionary::Object::New) {
 
62
    m_id = -1;
 
63
  }
 
64
};
 
65
 
 
66
/**
 
67
 * Column
 
68
 */
 
69
class NdbColumnImpl : public NdbDictionary::Column {
 
70
public:
 
71
  NdbColumnImpl();
 
72
  NdbColumnImpl(NdbDictionary::Column &); // This is not a copy constructor
 
73
  ~NdbColumnImpl();
 
74
  NdbColumnImpl& operator=(const NdbColumnImpl&);
 
75
  void init(Type t = Unsigned);
 
76
  
 
77
  int m_attrId;
 
78
  BaseString m_name;
 
79
  NdbDictionary::Column::Type m_type;
 
80
  int m_precision;
 
81
  int m_scale;
 
82
  int m_length;
 
83
  int m_column_no;
 
84
  CHARSET_INFO * m_cs;          // not const in MySQL
 
85
  
 
86
  bool m_pk;
 
87
  bool m_distributionKey;
 
88
  bool m_nullable;
 
89
  bool m_autoIncrement;
 
90
  Uint64 m_autoIncrementInitialValue;
 
91
  BaseString m_defaultValue;
 
92
  NdbTableImpl * m_blobTable;
 
93
 
 
94
  /**
 
95
   * Internal types and sizes, and aggregates
 
96
   */
 
97
  Uint32 m_attrSize;            // element size (size when arraySize==1)
 
98
  Uint32 m_arraySize;           // length or maxlength+1/2 for Var* types
 
99
  Uint32 m_arrayType;           // NDB_ARRAYTYPE_FIXED or _VAR
 
100
  Uint32 m_storageType;         // NDB_STORAGETYPE_MEMORY or _DISK
 
101
  /*
 
102
   * NdbTableImpl: if m_pk, 0-based index of key in m_attrId order
 
103
   * NdbIndexImpl: m_column_no of primary table column
 
104
   */
 
105
  Uint32 m_keyInfoPos;
 
106
  // TODO: use bits in attr desc 2
 
107
  bool getInterpretableType() const ;
 
108
  bool getCharType() const;
 
109
  bool getStringType() const;
 
110
  bool getBlobType() const;
 
111
 
 
112
  /**
 
113
   * Equality/assign
 
114
   */
 
115
  bool equal(const NdbColumnImpl&) const;
 
116
 
 
117
  static NdbColumnImpl & getImpl(NdbDictionary::Column & t);
 
118
  static const NdbColumnImpl & getImpl(const NdbDictionary::Column & t);
 
119
  NdbDictionary::Column * m_facade;
 
120
 
 
121
  static NdbDictionary::Column * create_pseudo(const char *);
 
122
 
 
123
  // Get total length in bytes, used by NdbOperation
 
124
  bool get_var_length(const void* value, Uint32& len) const;
 
125
};
 
126
 
 
127
class NdbTableImpl : public NdbDictionary::Table, public NdbDictObjectImpl {
 
128
public:
 
129
  NdbTableImpl();
 
130
  NdbTableImpl(NdbDictionary::Table &);
 
131
  ~NdbTableImpl();
 
132
  
 
133
  void init();
 
134
  int setName(const char * name);
 
135
  const char * getName() const;
 
136
  void setFragmentCount(Uint32 count);
 
137
  Uint32 getFragmentCount() const;
 
138
  int setFrm(const void* data, Uint32 len);
 
139
  const void * getFrmData() const;
 
140
  Uint32 getFrmLength() const;
 
141
  int setFragmentData(const void* data, Uint32 len);
 
142
  const void * getFragmentData() const;
 
143
  Uint32 getFragmentDataLen() const;
 
144
  int setTablespaceNames(const void* data, Uint32 len);
 
145
  Uint32 getTablespaceNamesLen() const;
 
146
  const void * getTablespaceNames() const;
 
147
  int setTablespaceData(const void* data, Uint32 len);
 
148
  const void * getTablespaceData() const;
 
149
  Uint32 getTablespaceDataLen() const;
 
150
  int setRangeListData(const void* data, Uint32 len);
 
151
  const void * getRangeListData() const;
 
152
  Uint32 getRangeListDataLen() const;
 
153
 
 
154
  const char * getMysqlName() const;
 
155
  int updateMysqlName();
 
156
 
 
157
  int aggregate(NdbError& error);
 
158
  int validate(NdbError& error);
 
159
 
 
160
  Uint32 m_changeMask;
 
161
  Uint32 m_primaryTableId;
 
162
  BaseString m_internalName;
 
163
  BaseString m_externalName;
 
164
  BaseString m_mysqlName;
 
165
  BaseString m_newExternalName; // Used for alter table
 
166
  UtilBuffer m_frm; 
 
167
  UtilBuffer m_newFrm;       // Used for alter table
 
168
  UtilBuffer m_ts_name;      //Tablespace Names
 
169
  UtilBuffer m_new_ts_name;  //Tablespace Names
 
170
  UtilBuffer m_ts;           //TablespaceData
 
171
  UtilBuffer m_new_ts;       //TablespaceData
 
172
  UtilBuffer m_fd;           //FragmentData
 
173
  UtilBuffer m_new_fd;       //FragmentData
 
174
  UtilBuffer m_range;        //Range Or List Array
 
175
  UtilBuffer m_new_range;    //Range Or List Array
 
176
  NdbDictionary::Object::FragmentType m_fragmentType;
 
177
 
 
178
  /**
 
179
   * 
 
180
   */
 
181
  Uint32 m_columnHashMask;
 
182
  Vector<Uint32> m_columnHash;
 
183
  Vector<NdbColumnImpl *> m_columns;
 
184
  void computeAggregates();
 
185
  int buildColumnHash(); 
 
186
 
 
187
  /**
 
188
   * Fragment info
 
189
   */
 
190
  Uint32 m_hashValueMask;
 
191
  Uint32 m_hashpointerValue;
 
192
  Vector<Uint16> m_fragments;
 
193
 
 
194
  Uint64 m_max_rows;
 
195
  Uint64 m_min_rows;
 
196
  Uint32 m_default_no_part_flag;
 
197
  bool m_linear_flag;
 
198
  bool m_logging;
 
199
  bool m_temporary;
 
200
  bool m_row_gci;
 
201
  bool m_row_checksum;
 
202
  bool m_force_var_part;
 
203
  int m_kvalue;
 
204
  int m_minLoadFactor;
 
205
  int m_maxLoadFactor;
 
206
  Uint16 m_keyLenInWords;
 
207
  Uint16 m_fragmentCount;
 
208
  Uint8 m_single_user_mode;
 
209
 
 
210
  NdbIndexImpl * m_index;
 
211
  NdbColumnImpl * getColumn(unsigned attrId);
 
212
  NdbColumnImpl * getColumn(const char * name);
 
213
  const NdbColumnImpl * getColumn(unsigned attrId) const;
 
214
  const NdbColumnImpl * getColumn(const char * name) const;
 
215
  
 
216
  /**
 
217
   * Index only stuff
 
218
   */
 
219
  BaseString m_primaryTable;
 
220
  NdbDictionary::Object::Type m_indexType;
 
221
 
 
222
  /**
 
223
   * Aggregates
 
224
   */
 
225
  Uint8 m_noOfKeys;
 
226
  // if all pk = dk then this is zero!
 
227
  Uint8 m_noOfDistributionKeys;
 
228
  Uint8 m_noOfBlobs;
 
229
  Uint8 m_noOfDiskColumns;
 
230
  Uint8 m_replicaCount;
 
231
 
 
232
  /**
 
233
   * Equality/assign
 
234
   */
 
235
  bool equal(const NdbTableImpl&) const;
 
236
  int assign(const NdbTableImpl&);
 
237
 
 
238
  static NdbTableImpl & getImpl(NdbDictionary::Table & t);
 
239
  static NdbTableImpl & getImpl(const NdbDictionary::Table & t);
 
240
  NdbDictionary::Table * m_facade;
 
241
  
 
242
  /**
 
243
   * Return count
 
244
   */
 
245
  Uint32 get_nodes(Uint32 hashValue, const Uint16** nodes) const ;
 
246
 
 
247
  /**
 
248
   * Disk stuff
 
249
   */
 
250
  BaseString m_tablespace_name;
 
251
  Uint32 m_tablespace_id;
 
252
  Uint32 m_tablespace_version;
 
253
};
 
254
 
 
255
class NdbIndexImpl : public NdbDictionary::Index, public NdbDictObjectImpl {
 
256
public:
 
257
  NdbIndexImpl();
 
258
  NdbIndexImpl(NdbDictionary::Index &);
 
259
  ~NdbIndexImpl();
 
260
 
 
261
  void init();
 
262
  int setName(const char * name);
 
263
  const char * getName() const;
 
264
  int setTable(const char * table);
 
265
  const char * getTable() const;
 
266
  const NdbTableImpl * getIndexTable() const;
 
267
 
 
268
  BaseString m_internalName;
 
269
  BaseString m_externalName;
 
270
  BaseString m_tableName;
 
271
  Uint32 m_table_id;
 
272
  Uint32 m_table_version;
 
273
  Vector<NdbColumnImpl *> m_columns;
 
274
  Vector<int> m_key_ids;
 
275
 
 
276
  bool m_logging;
 
277
  bool m_temporary;
 
278
  
 
279
  NdbTableImpl * m_table;
 
280
  
 
281
  static NdbIndexImpl & getImpl(NdbDictionary::Index & t);
 
282
  static NdbIndexImpl & getImpl(const NdbDictionary::Index & t);
 
283
  NdbDictionary::Index * m_facade;
 
284
};
 
285
 
 
286
class NdbEventImpl : public NdbDictionary::Event, public NdbDictObjectImpl {
 
287
  friend class NdbDictInterface;
 
288
  friend class NdbDictionaryImpl;
 
289
  friend class NdbEventOperation;
 
290
  friend class NdbEventOperationImpl;
 
291
  friend class NdbEventBuffer;
 
292
  friend class EventBufData_hash;
 
293
  friend class NdbBlob;
 
294
public:
 
295
  NdbEventImpl();
 
296
  NdbEventImpl(NdbDictionary::Event &);
 
297
  ~NdbEventImpl();
 
298
 
 
299
  void init();
 
300
  int setName(const char * name);
 
301
  const char * getName() const;
 
302
  int setTable(const NdbDictionary::Table& table);
 
303
  const NdbDictionary::Table * getTable() const;
 
304
  int setTable(const char * table);
 
305
  const char * getTableName() const;
 
306
  void addTableEvent(const NdbDictionary::Event::TableEvent t);
 
307
  bool getTableEvent(const NdbDictionary::Event::TableEvent t) const;
 
308
  void setDurability(NdbDictionary::Event::EventDurability d);
 
309
  NdbDictionary::Event::EventDurability  getDurability() const;
 
310
  void setReport(NdbDictionary::Event::EventReport r);
 
311
  NdbDictionary::Event::EventReport  getReport() const;
 
312
  int getNoOfEventColumns() const;
 
313
  const NdbDictionary::Column * getEventColumn(unsigned no) const;
 
314
 
 
315
  void print() {
 
316
    ndbout_c("NdbEventImpl: id=%d, key=%d",
 
317
             m_eventId,
 
318
             m_eventKey);
 
319
  };
 
320
 
 
321
  Uint32 m_eventId;
 
322
  Uint32 m_eventKey;
 
323
  AttributeMask m_attrListBitmask;
 
324
  Uint32 m_table_id;
 
325
  Uint32 m_table_version;
 
326
  BaseString m_name;
 
327
  Uint32 mi_type;
 
328
  NdbDictionary::Event::EventDurability m_dur;
 
329
  NdbDictionary::Event::EventReport m_rep;
 
330
  bool m_mergeEvents;
 
331
 
 
332
  BaseString m_tableName;
 
333
  Vector<NdbColumnImpl *> m_columns;
 
334
  Vector<unsigned> m_attrIds;
 
335
 
 
336
  static NdbEventImpl & getImpl(NdbDictionary::Event & t);
 
337
  static NdbEventImpl & getImpl(const NdbDictionary::Event & t);
 
338
  NdbDictionary::Event * m_facade;
 
339
private:
 
340
  NdbTableImpl *m_tableImpl;
 
341
  void setTable(NdbTableImpl *tableImpl);
 
342
};
 
343
 
 
344
struct NdbFilegroupImpl : public NdbDictObjectImpl {
 
345
  NdbFilegroupImpl(NdbDictionary::Object::Type t);
 
346
 
 
347
  BaseString m_name;
 
348
  NdbDictionary::AutoGrowSpecification m_grow_spec;
 
349
 
 
350
  union {
 
351
    Uint32 m_extent_size;
 
352
    Uint32 m_undo_buffer_size;
 
353
  };
 
354
 
 
355
  BaseString m_logfile_group_name;
 
356
  Uint32 m_logfile_group_id;
 
357
  Uint32 m_logfile_group_version;
 
358
  Uint64 m_undo_free_words;
 
359
};
 
360
 
 
361
class NdbTablespaceImpl : public NdbDictionary::Tablespace, 
 
362
                          public NdbFilegroupImpl {
 
363
public:
 
364
  NdbTablespaceImpl();
 
365
  NdbTablespaceImpl(NdbDictionary::Tablespace &);
 
366
  ~NdbTablespaceImpl();
 
367
 
 
368
  int assign(const NdbTablespaceImpl&);
 
369
 
 
370
  static NdbTablespaceImpl & getImpl(NdbDictionary::Tablespace & t);
 
371
  static const NdbTablespaceImpl & getImpl(const NdbDictionary::Tablespace &);
 
372
  NdbDictionary::Tablespace * m_facade;
 
373
};
 
374
 
 
375
class NdbLogfileGroupImpl : public NdbDictionary::LogfileGroup, 
 
376
                            public NdbFilegroupImpl {
 
377
public:
 
378
  NdbLogfileGroupImpl();
 
379
  NdbLogfileGroupImpl(NdbDictionary::LogfileGroup &);
 
380
  ~NdbLogfileGroupImpl();
 
381
 
 
382
  int assign(const NdbLogfileGroupImpl&);
 
383
 
 
384
  static NdbLogfileGroupImpl & getImpl(NdbDictionary::LogfileGroup & t);
 
385
  static const NdbLogfileGroupImpl& getImpl(const 
 
386
                                            NdbDictionary::LogfileGroup&);
 
387
  NdbDictionary::LogfileGroup * m_facade;
 
388
};
 
389
 
 
390
struct NdbFileImpl : public NdbDictObjectImpl {
 
391
  NdbFileImpl(NdbDictionary::Object::Type t);
 
392
 
 
393
  Uint64 m_size;
 
394
  Uint64 m_free;
 
395
  BaseString m_path;
 
396
  BaseString m_filegroup_name;
 
397
  Uint32 m_filegroup_id;
 
398
  Uint32 m_filegroup_version;
 
399
};
 
400
 
 
401
class NdbDatafileImpl : public NdbDictionary::Datafile, public NdbFileImpl {
 
402
public:
 
403
  NdbDatafileImpl();
 
404
  NdbDatafileImpl(NdbDictionary::Datafile &);
 
405
  ~NdbDatafileImpl();
 
406
 
 
407
  int assign(const NdbDatafileImpl&);
 
408
 
 
409
  static NdbDatafileImpl & getImpl(NdbDictionary::Datafile & t);
 
410
  static const NdbDatafileImpl & getImpl(const NdbDictionary::Datafile & t);
 
411
  NdbDictionary::Datafile * m_facade;
 
412
};
 
413
 
 
414
class NdbUndofileImpl : public NdbDictionary::Undofile, public NdbFileImpl {
 
415
public:
 
416
  NdbUndofileImpl();
 
417
  NdbUndofileImpl(NdbDictionary::Undofile &);
 
418
  ~NdbUndofileImpl();
 
419
 
 
420
  int assign(const NdbUndofileImpl&);
 
421
 
 
422
  static NdbUndofileImpl & getImpl(NdbDictionary::Undofile & t);
 
423
  static const NdbUndofileImpl & getImpl(const NdbDictionary::Undofile & t);
 
424
  NdbDictionary::Undofile * m_facade;
 
425
};
 
426
 
 
427
class NdbDictInterface {
 
428
public:
 
429
  NdbDictInterface(NdbError& err) : m_error(err) {
 
430
    m_reference = 0;
 
431
    m_masterNodeId = 0;
 
432
    m_transporter= NULL;
 
433
  }
 
434
  ~NdbDictInterface();
 
435
  
 
436
  bool setTransporter(class Ndb * ndb, class TransporterFacade * tf);
 
437
  bool setTransporter(class TransporterFacade * tf);
 
438
  
 
439
  // To abstract the stuff thats made in all create/drop/lists below
 
440
  int dictSignal(NdbApiSignal* signal, LinearSectionPtr ptr[3], int secs,
 
441
                 int nodeId, // -1 any, 0 = master, >1 = specified
 
442
                 WaitSignalType wst,
 
443
                 int timeout, Uint32 RETRIES,
 
444
                 const int *errcodes = 0, int temporaryMask = 0);
 
445
 
 
446
  int createOrAlterTable(class Ndb & ndb, NdbTableImpl &, bool alter);
 
447
 
 
448
  int createTable(class Ndb & ndb, NdbTableImpl &);
 
449
  int alterTable(class Ndb & ndb, NdbTableImpl &);
 
450
  int dropTable(const NdbTableImpl &);
 
451
 
 
452
  int createIndex(class Ndb & ndb, const NdbIndexImpl &, const NdbTableImpl &);
 
453
  int dropIndex(const NdbIndexImpl &, const NdbTableImpl &);
 
454
  
 
455
  int createEvent(class Ndb & ndb, NdbEventImpl &, int getFlag);
 
456
  int dropEvent(const NdbEventImpl &);
 
457
  int dropEvent(NdbApiSignal* signal, LinearSectionPtr ptr[3], int noLSP);
 
458
 
 
459
  int executeSubscribeEvent(class Ndb & ndb, NdbEventOperationImpl &);
 
460
  int stopSubscribeEvent(class Ndb & ndb, NdbEventOperationImpl &);
 
461
  
 
462
  int listObjects(NdbDictionary::Dictionary::List& list, Uint32 requestData, bool fullyQualifiedNames);
 
463
  int listObjects(NdbApiSignal* signal);
 
464
  
 
465
  NdbTableImpl * getTable(int tableId, bool fullyQualifiedNames);
 
466
  NdbTableImpl * getTable(const BaseString& name, bool fullyQualifiedNames);
 
467
  NdbTableImpl * getTable(class NdbApiSignal * signal, 
 
468
                          LinearSectionPtr ptr[3],
 
469
                          Uint32 noOfSections, bool fullyQualifiedNames);
 
470
 
 
471
  int forceGCPWait();
 
472
 
 
473
  static int parseTableInfo(NdbTableImpl ** dst, 
 
474
                            const Uint32 * data, Uint32 len,
 
475
                            bool fullyQualifiedNames,
 
476
                            Uint32 version= 0xFFFFFFFF);
 
477
 
 
478
  static int parseFileInfo(NdbFileImpl &dst,
 
479
                           const Uint32 * data, Uint32 len);
 
480
 
 
481
  static int parseFilegroupInfo(NdbFilegroupImpl &dst,
 
482
                                const Uint32 * data, Uint32 len);
 
483
  
 
484
  int create_file(const NdbFileImpl &, const NdbFilegroupImpl&, 
 
485
                  bool overwrite, NdbDictObjectImpl*);
 
486
  int drop_file(const NdbFileImpl &);
 
487
  int create_filegroup(const NdbFilegroupImpl &, NdbDictObjectImpl*);
 
488
  int drop_filegroup(const NdbFilegroupImpl &);
 
489
  
 
490
  int get_filegroup(NdbFilegroupImpl&, NdbDictionary::Object::Type, Uint32);
 
491
  int get_filegroup(NdbFilegroupImpl&,NdbDictionary::Object::Type,const char*);
 
492
  int get_file(NdbFileImpl&, NdbDictionary::Object::Type, int, int);
 
493
  int get_file(NdbFileImpl&, NdbDictionary::Object::Type, int, const char *);
 
494
  
 
495
  static int create_index_obj_from_table(NdbIndexImpl ** dst, 
 
496
                                         NdbTableImpl* index_table,
 
497
                                         const NdbTableImpl* primary_table);
 
498
  
 
499
  const NdbError &getNdbError() const;  
 
500
  NdbError & m_error;
 
501
private:
 
502
  Uint32 m_reference;
 
503
  Uint32 m_masterNodeId;
 
504
  
 
505
  NdbWaiter m_waiter;
 
506
  class TransporterFacade * m_transporter;
 
507
  
 
508
  friend class Ndb;
 
509
  friend class NdbDictionaryImpl;
 
510
  static void execSignal(void* dictImpl, 
 
511
                         class NdbApiSignal* signal, 
 
512
                         struct LinearSectionPtr ptr[3]);
 
513
  
 
514
  static void execNodeStatus(void* dictImpl, Uint32, 
 
515
                             bool alive, bool nfCompleted);  
 
516
  
 
517
  void execGET_TABINFO_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
518
  void execGET_TABINFO_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
519
  void execCREATE_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
520
  void execCREATE_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
521
  void execALTER_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
522
  void execALTER_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
523
 
 
524
  void execCREATE_INDX_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
525
  void execCREATE_INDX_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
526
  void execDROP_INDX_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
527
  void execDROP_INDX_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
528
 
 
529
  void execCREATE_EVNT_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
530
  void execCREATE_EVNT_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
531
  void execSUB_START_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
532
  void execSUB_START_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
533
  void execSUB_STOP_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
534
  void execSUB_STOP_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
535
  void execDROP_EVNT_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
536
  void execDROP_EVNT_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
537
 
 
538
  void execDROP_TABLE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
539
  void execDROP_TABLE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
540
  void execLIST_TABLES_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
541
 
 
542
  void execCREATE_FILE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
543
  void execCREATE_FILE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
544
  
 
545
  void execCREATE_FILEGROUP_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
546
  void execCREATE_FILEGROUP_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
547
 
 
548
  void execDROP_FILE_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
549
  void execDROP_FILE_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
550
  
 
551
  void execDROP_FILEGROUP_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
552
  void execDROP_FILEGROUP_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
553
  
 
554
  void execWAIT_GCP_CONF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
555
  void execWAIT_GCP_REF(NdbApiSignal *, LinearSectionPtr ptr[3]);
 
556
 
 
557
  Uint32 m_fragmentId;
 
558
  UtilBuffer m_buffer;
 
559
};
 
560
 
 
561
class NdbDictionaryImpl;
 
562
class GlobalCacheInitObject
 
563
{
 
564
public:
 
565
  NdbDictionaryImpl *m_dict;
 
566
  const BaseString &m_name;
 
567
  GlobalCacheInitObject(NdbDictionaryImpl *dict,
 
568
                        const BaseString &name) :
 
569
    m_dict(dict),
 
570
    m_name(name)
 
571
  {}
 
572
  virtual ~GlobalCacheInitObject() {}
 
573
  virtual int init(NdbTableImpl &tab) const = 0;
 
574
};
 
575
 
 
576
class NdbDictionaryImpl : public NdbDictionary::Dictionary {
 
577
public:
 
578
  NdbDictionaryImpl(Ndb &ndb);
 
579
  NdbDictionaryImpl(Ndb &ndb, NdbDictionary::Dictionary & f);
 
580
  ~NdbDictionaryImpl();
 
581
 
 
582
  bool setTransporter(class Ndb * ndb, class TransporterFacade * tf);
 
583
  bool setTransporter(class TransporterFacade * tf);
 
584
 
 
585
  int createTable(NdbTableImpl &t);
 
586
  int createBlobTables(NdbTableImpl& org, NdbTableImpl& created);
 
587
  int alterTable(NdbTableImpl &t);
 
588
  int dropTable(const char * name);
 
589
  int dropTable(NdbTableImpl &);
 
590
  int dropBlobTables(NdbTableImpl &);
 
591
  int invalidateObject(NdbTableImpl &);
 
592
  int removeCachedObject(NdbTableImpl &);
 
593
 
 
594
  int createIndex(NdbIndexImpl &ix);
 
595
  int createIndex(NdbIndexImpl &ix, NdbTableImpl & tab);
 
596
  int dropIndex(const char * indexName, 
 
597
                const char * tableName);
 
598
  int dropIndex(NdbIndexImpl &, const char * tableName);
 
599
  NdbTableImpl * getIndexTable(NdbIndexImpl * index, 
 
600
                               NdbTableImpl * table);
 
601
 
 
602
  int createEvent(NdbEventImpl &);
 
603
  int createBlobEvents(NdbEventImpl &);
 
604
  int dropEvent(const char * eventName);
 
605
  int dropEvent(const NdbEventImpl &);
 
606
  int dropBlobEvents(const NdbEventImpl &);
 
607
 
 
608
  int executeSubscribeEvent(NdbEventOperationImpl &);
 
609
  int stopSubscribeEvent(NdbEventOperationImpl &);
 
610
 
 
611
  int forceGCPWait();
 
612
 
 
613
  int listObjects(List& list, NdbDictionary::Object::Type type);
 
614
  int listIndexes(List& list, Uint32 indexId);
 
615
 
 
616
  NdbTableImpl * getTableGlobal(const char * tableName);
 
617
  NdbIndexImpl * getIndexGlobal(const char * indexName,
 
618
                                NdbTableImpl &ndbtab);
 
619
  int alterTableGlobal(NdbTableImpl &orig_impl, NdbTableImpl &impl);
 
620
  int dropTableGlobal(NdbTableImpl &);
 
621
  int dropIndexGlobal(NdbIndexImpl & impl);
 
622
  int releaseTableGlobal(NdbTableImpl & impl, int invalidate);
 
623
  int releaseIndexGlobal(NdbIndexImpl & impl, int invalidate);
 
624
 
 
625
  NdbTableImpl * getTable(const char * tableName, void **data= 0);
 
626
  NdbTableImpl * getBlobTable(const NdbTableImpl&, uint col_no);
 
627
  NdbTableImpl * getBlobTable(uint tab_id, uint col_no);
 
628
  void putTable(NdbTableImpl *impl);
 
629
  int getBlobTables(NdbTableImpl &);
 
630
  Ndb_local_table_info*
 
631
    get_local_table_info(const BaseString& internalTableName);
 
632
  NdbIndexImpl * getIndex(const char * indexName,
 
633
                          const char * tableName);
 
634
  NdbIndexImpl * getIndex(const char * indexName, const NdbTableImpl& prim);
 
635
  NdbEventImpl * getEvent(const char * eventName, NdbTableImpl* = NULL);
 
636
  NdbEventImpl * getBlobEvent(const NdbEventImpl& ev, uint col_no);
 
637
  NdbEventImpl * getEventImpl(const char * internalName);
 
638
 
 
639
  int createDatafile(const NdbDatafileImpl &, bool force, NdbDictObjectImpl*);
 
640
  int dropDatafile(const NdbDatafileImpl &);
 
641
  int createUndofile(const NdbUndofileImpl &, bool force, NdbDictObjectImpl*);
 
642
  int dropUndofile(const NdbUndofileImpl &);
 
643
 
 
644
  int createTablespace(const NdbTablespaceImpl &, NdbDictObjectImpl*);
 
645
  int dropTablespace(const NdbTablespaceImpl &);
 
646
 
 
647
  int createLogfileGroup(const NdbLogfileGroupImpl &, NdbDictObjectImpl*);
 
648
  int dropLogfileGroup(const NdbLogfileGroupImpl &);
 
649
  
 
650
  const NdbError & getNdbError() const;
 
651
  NdbError m_error;
 
652
  Uint32 m_local_table_data_size;
 
653
 
 
654
  LocalDictCache m_localHash;
 
655
  GlobalDictCache * m_globalHash;
 
656
 
 
657
  static NdbDictionaryImpl & getImpl(NdbDictionary::Dictionary & t);
 
658
  static const NdbDictionaryImpl & getImpl(const NdbDictionary::Dictionary &t);
 
659
  NdbDictionary::Dictionary * m_facade;
 
660
 
 
661
  NdbDictInterface m_receiver;
 
662
  Ndb & m_ndb;
 
663
 
 
664
  NdbIndexImpl* getIndexImpl(const char * externalName,
 
665
                             const BaseString& internalName,
 
666
                             NdbTableImpl &tab,
 
667
                             NdbTableImpl &prim);
 
668
  NdbIndexImpl * getIndexImpl(const char * name,
 
669
                              const BaseString& internalName);
 
670
private:
 
671
  NdbTableImpl * fetchGlobalTableImplRef(const GlobalCacheInitObject &obj);
 
672
};
 
673
 
 
674
inline
 
675
NdbEventImpl &
 
676
NdbEventImpl::getImpl(const NdbDictionary::Event & t){
 
677
  return t.m_impl;
 
678
}
 
679
 
 
680
inline
 
681
NdbEventImpl &
 
682
NdbEventImpl::getImpl(NdbDictionary::Event & t){
 
683
  return t.m_impl;
 
684
}
 
685
 
 
686
inline
 
687
NdbColumnImpl &
 
688
NdbColumnImpl::getImpl(NdbDictionary::Column & t){
 
689
  return t.m_impl;
 
690
}
 
691
 
 
692
inline
 
693
const NdbColumnImpl &
 
694
NdbColumnImpl::getImpl(const NdbDictionary::Column & t){
 
695
  return t.m_impl;
 
696
}
 
697
 
 
698
inline
 
699
bool 
 
700
NdbColumnImpl::getInterpretableType() const {
 
701
  return (m_type == NdbDictionary::Column::Unsigned ||
 
702
          m_type == NdbDictionary::Column::Bigunsigned);
 
703
}
 
704
 
 
705
inline
 
706
bool 
 
707
NdbColumnImpl::getCharType() const {
 
708
  return (m_type == NdbDictionary::Column::Char ||
 
709
          m_type == NdbDictionary::Column::Varchar ||
 
710
          m_type == NdbDictionary::Column::Text ||
 
711
          m_type == NdbDictionary::Column::Longvarchar);
 
712
}
 
713
 
 
714
inline
 
715
bool 
 
716
NdbColumnImpl::getStringType() const {
 
717
  return (m_type == NdbDictionary::Column::Char ||
 
718
          m_type == NdbDictionary::Column::Varchar ||
 
719
          m_type == NdbDictionary::Column::Longvarchar ||
 
720
          m_type == NdbDictionary::Column::Binary ||
 
721
          m_type == NdbDictionary::Column::Varbinary ||
 
722
          m_type == NdbDictionary::Column::Longvarbinary);
 
723
}
 
724
   
 
725
inline
 
726
bool 
 
727
NdbColumnImpl::getBlobType() const {
 
728
  return (m_type == NdbDictionary::Column::Blob ||
 
729
          m_type == NdbDictionary::Column::Text);
 
730
}
 
731
 
 
732
inline
 
733
bool
 
734
NdbColumnImpl::get_var_length(const void* value, Uint32& len) const
 
735
{
 
736
  Uint32 max_len = m_attrSize * m_arraySize;
 
737
  switch (m_arrayType) {
 
738
  case NDB_ARRAYTYPE_SHORT_VAR:
 
739
    len = 1 + *((Uint8*)value);
 
740
    break;
 
741
  case NDB_ARRAYTYPE_MEDIUM_VAR:
 
742
    len = 2 + uint2korr((char*)value);
 
743
    break;
 
744
  default:
 
745
    len = max_len;
 
746
    return true;
 
747
  }
 
748
  return (len <= max_len);
 
749
}
 
750
 
 
751
inline
 
752
NdbTableImpl &
 
753
NdbTableImpl::getImpl(NdbDictionary::Table & t){
 
754
  return t.m_impl;
 
755
}
 
756
 
 
757
inline
 
758
NdbTableImpl &
 
759
NdbTableImpl::getImpl(const NdbDictionary::Table & t){
 
760
  return t.m_impl;
 
761
}
 
762
 
 
763
inline
 
764
NdbColumnImpl *
 
765
NdbTableImpl::getColumn(unsigned attrId){
 
766
  if(m_columns.size() > attrId){
 
767
    return m_columns[attrId];
 
768
  }
 
769
  return 0;
 
770
}
 
771
 
 
772
inline
 
773
const char *
 
774
NdbTableImpl::getMysqlName() const
 
775
{
 
776
  return m_mysqlName.c_str();
 
777
}
 
778
 
 
779
inline
 
780
Uint32
 
781
Hash( const char* str ){
 
782
  Uint32 h = 0;
 
783
  Uint32 len = strlen(str);
 
784
  while(len >= 4){
 
785
    h = (h << 5) + h + str[0];
 
786
    h = (h << 5) + h + str[1];
 
787
    h = (h << 5) + h + str[2];
 
788
    h = (h << 5) + h + str[3];
 
789
    len -= 4;
 
790
    str += 4;
 
791
  }
 
792
  
 
793
  switch(len){
 
794
  case 3:
 
795
    h = (h << 5) + h + *str++;
 
796
  case 2:
 
797
    h = (h << 5) + h + *str++;
 
798
  case 1:
 
799
    h = (h << 5) + h + *str++;
 
800
  }
 
801
  return h + h;
 
802
}
 
803
 
 
804
 
 
805
inline
 
806
NdbColumnImpl *
 
807
NdbTableImpl::getColumn(const char * name){
 
808
 
 
809
  Uint32 sz = m_columns.size();
 
810
  NdbColumnImpl** cols = m_columns.getBase();
 
811
  const Uint32 * hashtable = m_columnHash.getBase();
 
812
 
 
813
  if(sz > 5 && false){
 
814
    Uint32 hashValue = Hash(name) & 0xFFFE;
 
815
    Uint32 bucket = hashValue & m_columnHashMask;
 
816
    bucket = (bucket < sz ? bucket : bucket - sz);
 
817
    hashtable += bucket;
 
818
    Uint32 tmp = * hashtable;
 
819
    if((tmp & 1) == 1 ){ // No chaining
 
820
      sz = 1;
 
821
    } else {
 
822
      sz = (tmp >> 16);
 
823
      hashtable += (tmp & 0xFFFE) >> 1;
 
824
      tmp = * hashtable;
 
825
    }
 
826
    do {
 
827
      if(hashValue == (tmp & 0xFFFE)){
 
828
        NdbColumnImpl* col = cols[tmp >> 16];
 
829
        if(strncmp(name, col->m_name.c_str(), col->m_name.length()) == 0){
 
830
          return col;
 
831
        }
 
832
      }
 
833
      hashtable++;
 
834
      tmp = * hashtable;
 
835
    } while(--sz > 0);
 
836
#if 0
 
837
    Uint32 dir = m_columnHash[bucket];
 
838
    Uint32 pos = bucket + ((dir & 0xFFFE) >> 1); 
 
839
    Uint32 cnt = dir >> 16;
 
840
    ndbout_c("col: %s hv: %x bucket: %d dir: %x pos: %d cnt: %d tmp: %d -> 0", 
 
841
             name, hashValue, bucket, dir, pos, cnt, tmp);
 
842
#endif
 
843
    return 0;
 
844
  } else {
 
845
    for(Uint32 i = 0; i<sz; i++){
 
846
      NdbColumnImpl* col = * cols++;
 
847
      if(col != 0 && strcmp(name, col->m_name.c_str()) == 0)
 
848
        return col;
 
849
    }
 
850
  }
 
851
  return 0;
 
852
}
 
853
 
 
854
inline
 
855
const NdbColumnImpl *
 
856
NdbTableImpl::getColumn(unsigned attrId) const {
 
857
  if(m_columns.size() > attrId){
 
858
    return m_columns[attrId];
 
859
  }
 
860
  return 0;
 
861
}
 
862
 
 
863
inline
 
864
const NdbColumnImpl *
 
865
NdbTableImpl::getColumn(const char * name) const {
 
866
  Uint32 sz = m_columns.size();
 
867
  NdbColumnImpl* const * cols = m_columns.getBase();
 
868
  for(Uint32 i = 0; i<sz; i++, cols++){
 
869
    NdbColumnImpl* col = * cols;
 
870
    if(col != 0 && strcmp(name, col->m_name.c_str()) == 0)
 
871
      return col;
 
872
  }
 
873
  return 0;
 
874
}
 
875
 
 
876
inline
 
877
NdbIndexImpl &
 
878
NdbIndexImpl::getImpl(NdbDictionary::Index & t){
 
879
  return t.m_impl;
 
880
}
 
881
 
 
882
inline
 
883
NdbIndexImpl &
 
884
NdbIndexImpl::getImpl(const NdbDictionary::Index & t){
 
885
  return t.m_impl;
 
886
}
 
887
 
 
888
inline
 
889
NdbDictionaryImpl &
 
890
NdbDictionaryImpl::getImpl(NdbDictionary::Dictionary & t){
 
891
  return t.m_impl;
 
892
}
 
893
 
 
894
inline
 
895
const NdbDictionaryImpl &
 
896
NdbDictionaryImpl::getImpl(const NdbDictionary::Dictionary & t){
 
897
  return t.m_impl;
 
898
}
 
899
 
 
900
/*****************************************************************
 
901
 * Inline:d getters
 
902
 */
 
903
 
 
904
class InitTable : public GlobalCacheInitObject
 
905
{
 
906
public:
 
907
  InitTable(NdbDictionaryImpl *dict,
 
908
            const BaseString &name) :
 
909
    GlobalCacheInitObject(dict, name)
 
910
  {}
 
911
  int init(NdbTableImpl &tab) const
 
912
  {
 
913
    return m_dict->getBlobTables(tab);
 
914
  }
 
915
};
 
916
 
 
917
inline
 
918
NdbTableImpl *
 
919
NdbDictionaryImpl::getTableGlobal(const char * table_name)
 
920
{
 
921
  const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
 
922
  return fetchGlobalTableImplRef(InitTable(this, internal_tabname));
 
923
}
 
924
 
 
925
inline
 
926
NdbTableImpl *
 
927
NdbDictionaryImpl::getTable(const char * table_name, void **data)
 
928
{
 
929
  DBUG_ENTER("NdbDictionaryImpl::getTable");
 
930
  DBUG_PRINT("enter", ("table: %s", table_name));
 
931
 
 
932
  if (unlikely(strchr(table_name, '$') != 0)) {
 
933
    Uint32 tab_id, col_no;
 
934
    if (is_ndb_blob_table(table_name, &tab_id, &col_no)) {
 
935
      NdbTableImpl* t = getBlobTable(tab_id, col_no);
 
936
      DBUG_RETURN(t);
 
937
    }
 
938
  }
 
939
 
 
940
  const BaseString internal_tabname(m_ndb.internalize_table_name(table_name));
 
941
  Ndb_local_table_info *info=
 
942
    get_local_table_info(internal_tabname);
 
943
  if (info == 0)
 
944
    DBUG_RETURN(0);
 
945
  if (data)
 
946
    *data= info->m_local_data;
 
947
  DBUG_RETURN(info->m_table_impl);
 
948
}
 
949
 
 
950
inline
 
951
Ndb_local_table_info * 
 
952
NdbDictionaryImpl::get_local_table_info(const BaseString& internalTableName)
 
953
{
 
954
  DBUG_ENTER("NdbDictionaryImpl::get_local_table_info");
 
955
  DBUG_PRINT("enter", ("table: %s", internalTableName.c_str()));
 
956
 
 
957
  Ndb_local_table_info *info= m_localHash.get(internalTableName.c_str());
 
958
  if (info == 0)
 
959
  {
 
960
    NdbTableImpl *tab=
 
961
      fetchGlobalTableImplRef(InitTable(this, internalTableName));
 
962
    if (tab)
 
963
    {
 
964
      info= Ndb_local_table_info::create(tab, m_local_table_data_size);
 
965
      if (info)
 
966
      {
 
967
        m_localHash.put(internalTableName.c_str(), info);
 
968
      }
 
969
    }
 
970
  }
 
971
  DBUG_RETURN(info); // autoincrement already initialized
 
972
}
 
973
 
 
974
class InitIndex : public GlobalCacheInitObject
 
975
{
 
976
public:
 
977
  const char *m_index_name;
 
978
  const NdbTableImpl &m_prim;
 
979
 
 
980
  InitIndex(const BaseString &internal_indexname,
 
981
            const char *index_name,
 
982
            const NdbTableImpl &prim) :
 
983
    GlobalCacheInitObject(0, internal_indexname),
 
984
    m_index_name(index_name),
 
985
    m_prim(prim)
 
986
    {}
 
987
  
 
988
  int init(NdbTableImpl &tab) const {
 
989
    DBUG_ENTER("InitIndex::init");
 
990
    DBUG_ASSERT(tab.m_indexType != NdbDictionary::Object::TypeUndefined);
 
991
    /**
 
992
     * Create index impl
 
993
     */
 
994
    NdbIndexImpl* idx;
 
995
    if(NdbDictInterface::create_index_obj_from_table(&idx, &tab, &m_prim) == 0)
 
996
    {
 
997
      idx->m_table = &tab;
 
998
      if (!idx->m_externalName.assign(m_index_name) ||
 
999
          !idx->m_internalName.assign(m_name))
 
1000
        DBUG_RETURN(4000);
 
1001
      tab.m_index = idx;
 
1002
      DBUG_RETURN(0);
 
1003
    }
 
1004
    DBUG_RETURN(1);
 
1005
  }
 
1006
};
 
1007
 
 
1008
inline
 
1009
NdbIndexImpl * 
 
1010
NdbDictionaryImpl::getIndexGlobal(const char * index_name,
 
1011
                                  NdbTableImpl &ndbtab)
 
1012
{
 
1013
  DBUG_ENTER("NdbDictionaryImpl::getIndexGlobal");
 
1014
  const BaseString
 
1015
    internal_indexname(m_ndb.internalize_index_name(&ndbtab, index_name));
 
1016
  int retry= 2;
 
1017
 
 
1018
  while (retry)
 
1019
  {
 
1020
    NdbTableImpl *tab=
 
1021
      fetchGlobalTableImplRef(InitIndex(internal_indexname,
 
1022
                                        index_name, ndbtab));
 
1023
    if (tab)
 
1024
    {
 
1025
      // tab->m_index sould be set. otherwise tab == 0
 
1026
      NdbIndexImpl *idx= tab->m_index;
 
1027
      if (idx->m_table_id != (unsigned)ndbtab.getObjectId() ||
 
1028
          idx->m_table_version != (unsigned)ndbtab.getObjectVersion())
 
1029
      {
 
1030
        releaseIndexGlobal(*idx, 1);
 
1031
        retry--;
 
1032
        continue;
 
1033
      }
 
1034
      DBUG_RETURN(idx);
 
1035
    }
 
1036
    break;
 
1037
  }
 
1038
  {
 
1039
    // Index not found, try old format
 
1040
    const BaseString
 
1041
      old_internal_indexname(m_ndb.old_internalize_index_name(&ndbtab, 
 
1042
                                                              index_name));
 
1043
    retry= 2;
 
1044
    while (retry)
 
1045
    {
 
1046
      NdbTableImpl *tab=
 
1047
        fetchGlobalTableImplRef(InitIndex(old_internal_indexname,
 
1048
                                          index_name, ndbtab));
 
1049
      if (tab)
 
1050
      {
 
1051
        // tab->m_index sould be set. otherwise tab == 0
 
1052
        NdbIndexImpl *idx= tab->m_index;
 
1053
        if (idx->m_table_id != (unsigned)ndbtab.getObjectId() ||
 
1054
            idx->m_table_version != (unsigned)ndbtab.getObjectVersion())
 
1055
        {
 
1056
          releaseIndexGlobal(*idx, 1);
 
1057
          retry--;
 
1058
          continue;
 
1059
        }
 
1060
        DBUG_RETURN(idx);
 
1061
      }
 
1062
      break;
 
1063
    }
 
1064
  }
 
1065
  m_error.code= 4243;
 
1066
  DBUG_RETURN(0);
 
1067
}
 
1068
 
 
1069
inline int
 
1070
NdbDictionaryImpl::releaseTableGlobal(NdbTableImpl & impl, int invalidate)
 
1071
{
 
1072
  DBUG_ENTER("NdbDictionaryImpl::releaseTableGlobal");
 
1073
  DBUG_PRINT("enter", ("internal_name: %s", impl.m_internalName.c_str()));
 
1074
  m_globalHash->lock();
 
1075
  m_globalHash->release(&impl, invalidate);
 
1076
  m_globalHash->unlock();
 
1077
  DBUG_RETURN(0);
 
1078
}
 
1079
 
 
1080
inline int
 
1081
NdbDictionaryImpl::releaseIndexGlobal(NdbIndexImpl & impl, int invalidate)
 
1082
{
 
1083
  DBUG_ENTER("NdbDictionaryImpl::releaseIndexGlobal");
 
1084
  DBUG_PRINT("enter", ("internal_name: %s", impl.m_internalName.c_str()));
 
1085
  m_globalHash->lock();
 
1086
  m_globalHash->release(impl.m_table, invalidate);
 
1087
  m_globalHash->unlock();
 
1088
  DBUG_RETURN(0);
 
1089
}
 
1090
 
 
1091
inline
 
1092
NdbIndexImpl * 
 
1093
NdbDictionaryImpl::getIndex(const char * index_name,
 
1094
                            const char * table_name)
 
1095
{
 
1096
  if (table_name == 0)
 
1097
  {
 
1098
    assert(0);
 
1099
    m_error.code= 4243;
 
1100
    return 0;
 
1101
  }
 
1102
  
 
1103
  
 
1104
  NdbTableImpl* prim = getTable(table_name);
 
1105
  if (prim == 0)
 
1106
  {
 
1107
    m_error.code= 4243;
 
1108
    return 0;
 
1109
  }
 
1110
 
 
1111
  return getIndex(index_name, *prim);
 
1112
}
 
1113
 
 
1114
inline
 
1115
NdbIndexImpl * 
 
1116
NdbDictionaryImpl::getIndex(const char* index_name,
 
1117
                            const NdbTableImpl& prim)
 
1118
{
 
1119
 
 
1120
  const BaseString
 
1121
    internal_indexname(m_ndb.internalize_index_name(&prim, index_name));
 
1122
 
 
1123
  Ndb_local_table_info *info= m_localHash.get(internal_indexname.c_str());
 
1124
  NdbTableImpl *tab;
 
1125
  if (info == 0)
 
1126
  {
 
1127
    tab= fetchGlobalTableImplRef(InitIndex(internal_indexname,
 
1128
                                           index_name,
 
1129
                                           prim));
 
1130
    if (!tab)
 
1131
      goto retry;
 
1132
 
 
1133
    info= Ndb_local_table_info::create(tab, 0);
 
1134
    if (!info)
 
1135
      goto retry;
 
1136
    m_localHash.put(internal_indexname.c_str(), info);
 
1137
  }
 
1138
  else
 
1139
    tab= info->m_table_impl;
 
1140
  
 
1141
  return tab->m_index;
 
1142
 
 
1143
retry:
 
1144
  // Index not found, try fetching it from current database
 
1145
  const BaseString
 
1146
    old_internal_indexname(m_ndb.old_internalize_index_name(&prim, index_name));
 
1147
 
 
1148
  info= m_localHash.get(old_internal_indexname.c_str());
 
1149
  if (info == 0)
 
1150
  {
 
1151
    tab= fetchGlobalTableImplRef(InitIndex(old_internal_indexname,
 
1152
                                           index_name,
 
1153
                                           prim));
 
1154
    if (!tab)
 
1155
      goto err;
 
1156
    
 
1157
    info= Ndb_local_table_info::create(tab, 0);
 
1158
    if (!info)
 
1159
      goto err;
 
1160
    m_localHash.put(old_internal_indexname.c_str(), info);
 
1161
  }
 
1162
  else
 
1163
    tab= info->m_table_impl;
 
1164
  
 
1165
  return tab->m_index;
 
1166
  
 
1167
err:
 
1168
  m_error.code= 4243;
 
1169
  return 0;
 
1170
}
 
1171
 
 
1172
inline
 
1173
NdbTablespaceImpl &
 
1174
NdbTablespaceImpl::getImpl(NdbDictionary::Tablespace & t){
 
1175
  return t.m_impl;
 
1176
}
 
1177
 
 
1178
inline
 
1179
const NdbTablespaceImpl &
 
1180
NdbTablespaceImpl::getImpl(const NdbDictionary::Tablespace & t){
 
1181
  return t.m_impl;
 
1182
}
 
1183
 
 
1184
inline
 
1185
NdbLogfileGroupImpl &
 
1186
NdbLogfileGroupImpl::getImpl(NdbDictionary::LogfileGroup & t){
 
1187
  return t.m_impl;
 
1188
}
 
1189
 
 
1190
inline
 
1191
const NdbLogfileGroupImpl &
 
1192
NdbLogfileGroupImpl::getImpl(const NdbDictionary::LogfileGroup & t){
 
1193
  return t.m_impl;
 
1194
}
 
1195
 
 
1196
inline
 
1197
NdbDatafileImpl &
 
1198
NdbDatafileImpl::getImpl(NdbDictionary::Datafile & t){
 
1199
  return t.m_impl;
 
1200
}
 
1201
 
 
1202
inline
 
1203
const NdbDatafileImpl &
 
1204
NdbDatafileImpl::getImpl(const NdbDictionary::Datafile & t){
 
1205
  return t.m_impl;
 
1206
}
 
1207
 
 
1208
inline
 
1209
NdbUndofileImpl &
 
1210
NdbUndofileImpl::getImpl(NdbDictionary::Undofile & t){
 
1211
  return t.m_impl;
 
1212
}
 
1213
 
 
1214
inline
 
1215
const NdbUndofileImpl &
 
1216
NdbUndofileImpl::getImpl(const NdbDictionary::Undofile & t){
 
1217
  return t.m_impl;
 
1218
}
 
1219
 
 
1220
#endif