File: storage_adapter.cc

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (651 lines) | stat: -rw-r--r-- 27,371 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/* Copyright (c) 2015, 2025, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is designed to work with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have either included with
   the program or referenced in the documentation.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#include "sql/dd/impl/cache/storage_adapter.h"

#include <assert.h>
#include <memory>
#include <string>

#include "mutex_lock.h"  // Mutex_lock
#include "my_compiler.h"

#include "my_inttypes.h"
#include "my_sys.h"
#include "mysql/components/services/log_builtins.h"
#include "sql/dd/cache/dictionary_client.h"       // Dictionary_client
#include "sql/dd/impl/bootstrap/bootstrap_ctx.h"  // bootstrap::DD_bootstrap_ctx
#include "sql/dd/impl/cache/cache_element.h"
#include "sql/dd/impl/raw/object_keys.h"           // Primary_id_key
#include "sql/dd/impl/raw/raw_record.h"            // Raw_record
#include "sql/dd/impl/raw/raw_table.h"             // Raw_table
#include "sql/dd/impl/sdi.h"                       // sdi::store() sdi::drop()
#include "sql/dd/impl/tables/character_sets.h"     // dd::tables::Character_sets
#include "sql/dd/impl/tables/collations.h"         // dd::tables::Collations
#include "sql/dd/impl/tables/column_statistics.h"  // dd::tables::Column_stat...
#include "sql/dd/impl/tables/events.h"             // dd::tables::Events
#include "sql/dd/impl/tables/index_stats.h"        // dd::tables::Index_stats
#include "sql/dd/impl/tables/resource_groups.h"  // dd::tables::Resource_groups
#include "sql/dd/impl/tables/routines.h"         // dd::tables::Routines
#include "sql/dd/impl/tables/schemata.h"         // dd::tables::Schemata
#include "sql/dd/impl/tables/spatial_reference_systems.h"  // dd::tables::Spatial...
#include "sql/dd/impl/tables/table_stats.h"  // dd::tables::Table_stats
#include "sql/dd/impl/tables/tables.h"       // dd::tables::Tables
#include "sql/dd/impl/tables/tablespaces.h"  // dd::tables::Tablespaces
#include "sql/dd/impl/transaction_impl.h"    // Transaction_ro
#include "sql/dd/impl/types/entity_object_impl.h"
#include "sql/dd/types/abstract_table.h"            // Abstract_table
#include "sql/dd/types/charset.h"                   // Charset
#include "sql/dd/types/collation.h"                 // Collation
#include "sql/dd/types/column_statistics.h"         // Column_statistics
#include "sql/dd/types/entity_object_table.h"       // Entity_object_table
#include "sql/dd/types/event.h"                     // Event
#include "sql/dd/types/function.h"                  // Routine, Function
#include "sql/dd/types/index_stat.h"                // Index_stat
#include "sql/dd/types/procedure.h"                 // Procedure
#include "sql/dd/types/schema.h"                    // Schema
#include "sql/dd/types/spatial_reference_system.h"  // Spatial_reference_system
#include "sql/dd/types/table.h"                     // Table
#include "sql/dd/types/table_stat.h"                // Table_stat
#include "sql/dd/types/tablespace.h"                // Tablespace
#include "sql/dd/types/view.h"                      // View
#include "sql/dd/upgrade_57/upgrade.h"              // allow_sdi_creation
#include "sql/debug_sync.h"                         // DEBUG_SYNC
#include "sql/error_handler.h"                      // Internal_error_handler
#include "sql/log.h"
#include "sql/sql_class.h"  // THD

namespace dd {
namespace cache {

Storage_adapter *Storage_adapter::instance() {
  static Storage_adapter s_instance;
  return &s_instance;
}

bool Storage_adapter::s_use_fake_storage = false;

// Generate a new object id for a registry partition.
template <typename T>
Object_id Storage_adapter::next_oid() {
  static Object_id next_oid = FIRST_OID;
  return next_oid++;
}

// Get the number of core objects in a registry partition.
template <typename T>
size_t Storage_adapter::core_size() {
  MUTEX_LOCK(lock, &m_lock);
  return m_core_registry.size<typename T::Cache_partition>();
}

// Get a dictionary object id from core storage.
template <typename T>
Object_id Storage_adapter::core_get_id(const typename T::Name_key &key) {
  Cache_element<typename T::Cache_partition> *element = nullptr;
  MUTEX_LOCK(lock, &m_lock);
  m_core_registry.get(key, &element);
  if (element) {
    assert(element->object());
    return element->object()->id();
  }
  return INVALID_OBJECT_ID;
}

// Get a dictionary object from core storage.
template <typename K, typename T>
void Storage_adapter::core_get(const K &key, const T **object) {
  assert(object);
  *object = nullptr;
  Cache_element<typename T::Cache_partition> *element = nullptr;
  MUTEX_LOCK(lock, &m_lock);
  m_core_registry.get(key, &element);
  if (element) {
    // Must clone the object here, otherwise evicting the object from
    // the shared cache will also make it vanish from the core storage.
    *object = dynamic_cast<const T *>(element->object())->clone();
  }
}

// Update the dictionary object for a dd entity in the core registry.
void Storage_adapter::core_update(const dd::Tablespace *new_tsp) {
  if (new_tsp->id() != MYSQL_TABLESPACE_DD_ID) {
    return;
  }

  Cache_element<typename dd::Tablespace::Cache_partition> *element = nullptr;
  typename dd::Tablespace::Id_key key(new_tsp->id());
  MUTEX_LOCK(lock, &m_lock);
  m_core_registry.get(key, &element);
  assert(element != nullptr);
  m_core_registry.remove(element);
  std::unique_ptr<const dd::Tablespace> old{element->object()};

  element->set_object(new_tsp->clone());
  element->recreate_keys();
  m_core_registry.put(element);
}

// Get a dictionary object from persistent storage.
template <typename K, typename T>
bool Storage_adapter::get(THD *thd, const K &key, enum_tx_isolation isolation,
                          bool bypass_core_registry, const T **object) {
  assert(object);
  *object = nullptr;

  if (!bypass_core_registry) {
    instance()->core_get(key, object);
    if (*object || s_use_fake_storage) return false;
  }

  // We may have a cache miss while checking for existing tables during
  // server start. At this stage, the object will be considered not existing.
  if (bootstrap::DD_bootstrap_ctx::instance().get_stage() <
      bootstrap::Stage::CREATED_TABLES)
    return false;

  // Start a DD transaction to get the object.
  Transaction_ro trx(thd, isolation);
  trx.otx.register_tables<T>();

  if (trx.otx.open_tables()) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  const Entity_object_table &table = T::DD_table::instance();
  // Get main object table.
  Raw_table *t = trx.otx.get_table(table.name());

  // Find record by the object-id.
  std::unique_ptr<Raw_record> r;
  if (t->find_record(key, r)) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  // Restore the object from the record.
  Entity_object *new_object = nullptr;
  if (r.get() &&
      table.restore_object_from_record(&trx.otx, *r.get(), &new_object)) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  // Delete the new object if dynamic cast fails.
  if (new_object) {
    // Here, a failing dynamic cast is not a legitimate situation.
    // In production, we report an error.
    *object = dynamic_cast<T *>(new_object);
    if (!*object) {
      /* purecov: begin inspected */
      my_error(ER_INVALID_DD_OBJECT, MYF(0), new_object->name().c_str());
      delete new_object;
      assert(false);
      return true;
      /* purecov: end */
    }
  }

  return false;
}

// Drop a dictionary object from core storage.
template <typename T>
void Storage_adapter::core_drop(THD *thd [[maybe_unused]], const T *object) {
  assert(s_use_fake_storage || thd->is_dd_system_thread());
  assert(bootstrap::DD_bootstrap_ctx::instance().get_stage() <=
         bootstrap::Stage::CREATED_TABLES);
  Cache_element<typename T::Cache_partition> *element = nullptr;
  MUTEX_LOCK(lock, &m_lock);

  // For unit tests, drop based on id to simulate behavior of persistent tables.
  // For storing core objects during bootstrap, drop based on names since id may
  // differ between scaffolding objects and persisted objects.
  if (s_use_fake_storage) {
    typename T::Id_key key;
    object->update_id_key(&key);
    m_core_registry.get(key, &element);
  } else {
    typename T::Name_key key;
    object->update_name_key(&key);
    m_core_registry.get(key, &element);
  }
  if (element) {
    m_core_registry.remove(element);
    delete element->object();
    delete element;
  }
}

// Drop a dictionary object from persistent storage.
template <typename T>
bool Storage_adapter::drop(THD *thd, const T *object) {
  if (s_use_fake_storage ||
      bootstrap::DD_bootstrap_ctx::instance().get_stage() <
          bootstrap::Stage::CREATED_TABLES) {
    instance()->core_drop(thd, object);
    return false;
  }

  if (object->impl()->validate()) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  if (sdi::drop(thd, object)) {
    return true;
  }

  // Drop the object from the dd tables. We need to switch transaction ctx to do
  // this.
  Update_dictionary_tables_ctx ctx(thd);
  ctx.otx.register_tables<T>();

  if (ctx.otx.open_tables() || object->impl()->drop(&ctx.otx)) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  return false;
}

// Store a dictionary object to core storage.
template <typename T>
void Storage_adapter::core_store(THD *thd, T *object) {
  assert(s_use_fake_storage || thd->is_dd_system_thread());
  assert(bootstrap::DD_bootstrap_ctx::instance().get_stage() <=
         bootstrap::Stage::CREATED_TABLES);
  Cache_element<typename T::Cache_partition> *element =
      new Cache_element<typename T::Cache_partition>();

  if (object->id() != INVALID_OBJECT_ID) {
    // For unit tests, drop old object (based on id) to simulate update.
    if (s_use_fake_storage) core_drop(thd, object);
  } else {
    dd::Entity_object_impl *object_impl =
        dynamic_cast<dd::Entity_object_impl *>(object);
    object_impl->set_id(next_oid<T>());
  }

  // Need to clone since core registry takes ownership
  element->set_object(object->clone());
  element->recreate_keys();
  MUTEX_LOCK(lock, &m_lock);
  m_core_registry.put(element);
}

// Re-map error messages emitted during DDL with innodb-read-only == 1.
class Open_dictionary_tables_error_handler : public Internal_error_handler {
 public:
  bool handle_condition(THD *, uint sql_errno, const char *,
                        Sql_condition::enum_severity_level *,
                        const char *) override {
    if (sql_errno == ER_OPEN_AS_READONLY) {
      my_error(ER_READ_ONLY_MODE, MYF(0));
      return true;
    }
    return false;
  }
};

// Store a dictionary object to persistent storage.
template <typename T>
bool Storage_adapter::store(THD *thd, T *object) {
  if (s_use_fake_storage ||
      bootstrap::DD_bootstrap_ctx::instance().get_stage() <
          bootstrap::Stage::CREATED_TABLES) {
    instance()->core_store(thd, object);
    return false;
  }

  if (object->impl()->validate()) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    return true;
  }

  // Store the object into the dd tables. We need to switch transaction
  // ctx to do this.
  Update_dictionary_tables_ctx ctx(thd);
  ctx.otx.register_tables<T>();
  DEBUG_SYNC(thd, "before_storing_dd_object");

  Open_dictionary_tables_error_handler error_handler;
  thd->push_internal_handler(&error_handler);
  if (ctx.otx.open_tables() || object->impl()->store(&ctx.otx)) {
    assert(thd->is_system_thread() || thd->killed || thd->is_error());
    thd->pop_internal_handler();
    return true;
  }
  thd->pop_internal_handler();

  // Do not create SDIs for tablespaces and tables while creating
  // dictionary entry during upgrade.
  if (bootstrap::DD_bootstrap_ctx::instance().get_stage() >
          bootstrap::Stage::CREATED_TABLES &&
      dd::upgrade_57::allow_sdi_creation() && sdi::store(thd, object))
    return true;

  return false;
}

// Sync a dictionary object from persistent to core storage.
template <typename T>
bool Storage_adapter::core_sync(THD *thd, const typename T::Name_key &key,
                                const T *object) {
  assert(thd->is_dd_system_thread());
  assert(bootstrap::DD_bootstrap_ctx::instance().get_stage() <=
         bootstrap::Stage::CREATED_TABLES);

  // Copy the name, needed for error output. The object has to be
  // dropped before get().
  String_type name(object->name());
  core_drop(thd, object);
  const typename T::Cache_partition *new_obj = nullptr;

  /*
    Fetch the object from persistent tables. The object was dropped
    from the core registry above, so we know get() will fetch it
    from the tables.

    There is a theoretical possibility of get() failing or sending
    back a nullptr if there has been a corruption or wrong usage
    (e.g. dropping a DD table), leaving one or more DD tables
    inaccessible. Assume, e.g., that the 'mysql.tables' table has
    been dropped. Then, the following will happen during restart:

    1. After creating the scaffolding, the meta data representing
       the DD tables is kept in the shared cache, secured by a
       scoped auto releaser in 'sync_meta_data()' in the bootstrapper
       (this is to make sure the meta data is not evicted during
       synchronization).
    2. We sync the DD tables, starting with 'mysql.character_sets'
       (because it is the first entry in the System_table_registry).
    3. Here in core_sync(), the entry in the core registry is
       removed. Then, we call get(), which will read the meta data
       from the persistent DD tables.
    4. While trying to fetch the meta data for the first table to
       be synced (i.e., 'mysql.character_sets'), we first open
       the tables that are needed to read the meta data for a table
       (i.e., we open the core tables). One of these tables is the
       'mysql.tables' table.
    5. While opening these tables, the server will fetch the meta
       data for them. The meta data for 'mysql.tables' is indeed
       found (because it was created as part of the scaffolding
       with the meta data now being in the shared cache), however,
       when opening the table in the storage engine, we get a
       failure because the SE knows nothing about this table, and
       is unable to open it.
  */
  if (get(thd, key, ISO_READ_COMMITTED, false, &new_obj) ||
      new_obj == nullptr) {
    LogErr(ERROR_LEVEL, ER_DD_METADATA_NOT_FOUND, name.c_str());
    return true;
  }

  Cache_element<typename T::Cache_partition> *element =
      new Cache_element<typename T::Cache_partition>();
  element->set_object(new_obj);
  element->recreate_keys();
  MUTEX_LOCK(lock, &m_lock);
  m_core_registry.put(element);
  return false;
}

// Remove and delete all elements and objects from core storage.
void Storage_adapter::erase_all() {
  MUTEX_LOCK(lock, &m_lock);
  instance()->m_core_registry.erase_all();
}

// Dump the contents of the core storage.
void Storage_adapter::dump() {
#ifndef NDEBUG
  MUTEX_LOCK(lock, &m_lock);
  fprintf(stderr, "================================\n");
  fprintf(stderr, "Storage adapter\n");
  m_core_registry.dump<dd::Tablespace>();
  m_core_registry.dump<dd::Schema>();
  m_core_registry.dump<dd::Abstract_table>();
  fprintf(stderr, "================================\n");
#endif
}

// Explicitly instantiate the type for the various usages.
template bool Storage_adapter::core_sync(THD *, const Table::Name_key &,
                                         const Table *);
template bool Storage_adapter::core_sync(THD *, const Tablespace::Name_key &,
                                         const Tablespace *);
template bool Storage_adapter::core_sync(THD *, const Schema::Name_key &,
                                         const Schema *);

template Object_id Storage_adapter::core_get_id<Table>(const Table::Name_key &);
template Object_id Storage_adapter::core_get_id<Schema>(
    const Schema::Name_key &);
template Object_id Storage_adapter::core_get_id<Tablespace>(
    const Tablespace::Name_key &);

template void Storage_adapter::core_get(dd::Item_name_key const &,
                                        const dd::Schema **);
template void Storage_adapter::core_get<dd::Item_name_key, dd::Abstract_table>(
    dd::Item_name_key const &, const dd::Abstract_table **);
template void Storage_adapter::core_get<dd::Global_name_key, dd::Tablespace>(
    dd::Global_name_key const &, const dd::Tablespace **);

template Object_id Storage_adapter::next_oid<Abstract_table>();
template Object_id Storage_adapter::next_oid<Table>();
template Object_id Storage_adapter::next_oid<View>();
template Object_id Storage_adapter::next_oid<Charset>();
template Object_id Storage_adapter::next_oid<Collation>();
template Object_id Storage_adapter::next_oid<Column_statistics>();
template Object_id Storage_adapter::next_oid<Event>();
template Object_id Storage_adapter::next_oid<Routine>();
template Object_id Storage_adapter::next_oid<Function>();
template Object_id Storage_adapter::next_oid<Procedure>();
template Object_id Storage_adapter::next_oid<Schema>();
template Object_id Storage_adapter::next_oid<Spatial_reference_system>();
template Object_id Storage_adapter::next_oid<Tablespace>();

template size_t Storage_adapter::core_size<Abstract_table>();
template size_t Storage_adapter::core_size<Table>();
template size_t Storage_adapter::core_size<Schema>();
template size_t Storage_adapter::core_size<Tablespace>();

template bool Storage_adapter::get<Abstract_table::Id_key, Abstract_table>(
    THD *, const Abstract_table::Id_key &, enum_tx_isolation, bool,
    const Abstract_table **);
template bool Storage_adapter::get<Abstract_table::Name_key, Abstract_table>(
    THD *, const Abstract_table::Name_key &, enum_tx_isolation, bool,
    const Abstract_table **);
template bool Storage_adapter::get<Abstract_table::Aux_key, Abstract_table>(
    THD *, const Abstract_table::Aux_key &, enum_tx_isolation, bool,
    const Abstract_table **);
template bool Storage_adapter::drop(THD *, const Abstract_table *);
template bool Storage_adapter::store(THD *, Abstract_table *);
template bool Storage_adapter::drop(THD *, const Table *);
template bool Storage_adapter::store(THD *, Table *);
template bool Storage_adapter::drop(THD *, const View *);
template bool Storage_adapter::store(THD *, View *);

template bool Storage_adapter::get<Charset::Id_key, Charset>(
    THD *, const Charset::Id_key &, enum_tx_isolation, bool, const Charset **);
template bool Storage_adapter::get<Charset::Name_key, Charset>(
    THD *, const Charset::Name_key &, enum_tx_isolation, bool,
    const Charset **);
template bool Storage_adapter::get<Charset::Aux_key, Charset>(
    THD *, const Charset::Aux_key &, enum_tx_isolation, bool, const Charset **);
template bool Storage_adapter::drop(THD *, const Charset *);
template bool Storage_adapter::store(THD *, Charset *);

template bool Storage_adapter::get<Collation::Id_key, Collation>(
    THD *, const Collation::Id_key &, enum_tx_isolation, bool,
    const Collation **);
template bool Storage_adapter::get<Collation::Name_key, Collation>(
    THD *, const Collation::Name_key &, enum_tx_isolation, bool,
    const Collation **);
template bool Storage_adapter::get<Collation::Aux_key, Collation>(
    THD *, const Collation::Aux_key &, enum_tx_isolation, bool,
    const Collation **);
template bool Storage_adapter::drop(THD *, const Collation *);
template bool Storage_adapter::store(THD *, Collation *);

template bool
Storage_adapter::get<Column_statistics::Id_key, Column_statistics>(
    THD *, const Column_statistics::Id_key &, enum_tx_isolation, bool,
    const Column_statistics **);
template bool
Storage_adapter::get<Column_statistics::Name_key, Column_statistics>(
    THD *, const Column_statistics::Name_key &, enum_tx_isolation, bool,
    const Column_statistics **);
template bool
Storage_adapter::get<Column_statistics::Aux_key, Column_statistics>(
    THD *, const Column_statistics::Aux_key &, enum_tx_isolation, bool,
    const Column_statistics **);
template bool Storage_adapter::drop(THD *, const Column_statistics *);
template bool Storage_adapter::store(THD *, Column_statistics *);

template bool Storage_adapter::get<Event::Id_key, Event>(THD *,
                                                         const Event::Id_key &,
                                                         enum_tx_isolation,
                                                         bool, const Event **);
template bool Storage_adapter::get<Event::Name_key, Event>(
    THD *, const Event::Name_key &, enum_tx_isolation, bool, const Event **);
template bool Storage_adapter::get<Event::Aux_key, Event>(
    THD *, const Event::Aux_key &, enum_tx_isolation, bool, const Event **);
template bool Storage_adapter::drop(THD *, const Event *);
template bool Storage_adapter::store(THD *, Event *);

template bool Storage_adapter::get<Resource_group::Id_key, Resource_group>(
    THD *, const Resource_group::Id_key &, enum_tx_isolation, bool,
    const Resource_group **);
template bool Storage_adapter::get<Resource_group::Name_key, Resource_group>(
    THD *, const Resource_group::Name_key &, enum_tx_isolation, bool,
    const Resource_group **);
template bool Storage_adapter::get<Resource_group::Aux_key, Resource_group>(
    THD *, const Resource_group::Aux_key &, enum_tx_isolation, bool,
    const Resource_group **);
template bool Storage_adapter::drop(THD *, const Resource_group *);
template bool Storage_adapter::store(THD *, Resource_group *);

template bool Storage_adapter::get<Routine::Id_key, Routine>(
    THD *, const Routine::Id_key &, enum_tx_isolation, bool, const Routine **);
template bool Storage_adapter::get<Routine::Name_key, Routine>(
    THD *, const Routine::Name_key &, enum_tx_isolation, bool,
    const Routine **);
template bool Storage_adapter::get<Routine::Aux_key, Routine>(
    THD *, const Routine::Aux_key &, enum_tx_isolation, bool, const Routine **);
template bool Storage_adapter::drop(THD *, const Routine *);
template bool Storage_adapter::store(THD *, Routine *);
template bool Storage_adapter::drop(THD *, const Function *);
template bool Storage_adapter::store(THD *, Function *);
template bool Storage_adapter::drop(THD *, const Procedure *);
template bool Storage_adapter::store(THD *, Procedure *);

template bool Storage_adapter::get<Schema::Id_key, Schema>(
    THD *, const Schema::Id_key &, enum_tx_isolation, bool, const Schema **);
template bool Storage_adapter::get<Schema::Name_key, Schema>(
    THD *, const Schema::Name_key &, enum_tx_isolation, bool, const Schema **);
template bool Storage_adapter::get<Schema::Aux_key, Schema>(
    THD *, const Schema::Aux_key &, enum_tx_isolation, bool, const Schema **);
template bool Storage_adapter::drop(THD *, const Schema *);
template bool Storage_adapter::store(THD *, Schema *);

template bool Storage_adapter::get<Spatial_reference_system::Id_key,
                                   Spatial_reference_system>(
    THD *, const Spatial_reference_system::Id_key &, enum_tx_isolation, bool,
    const Spatial_reference_system **);
template bool Storage_adapter::get<Spatial_reference_system::Name_key,
                                   Spatial_reference_system>(
    THD *, const Spatial_reference_system::Name_key &, enum_tx_isolation, bool,
    const Spatial_reference_system **);
template bool Storage_adapter::get<Spatial_reference_system::Aux_key,
                                   Spatial_reference_system>(
    THD *, const Spatial_reference_system::Aux_key &, enum_tx_isolation, bool,
    const Spatial_reference_system **);
template bool Storage_adapter::drop(THD *, const Spatial_reference_system *);
template bool Storage_adapter::store(THD *, Spatial_reference_system *);

template bool Storage_adapter::get<Tablespace::Id_key, Tablespace>(
    THD *, const Tablespace::Id_key &, enum_tx_isolation, bool,
    const Tablespace **);
template bool Storage_adapter::get<Tablespace::Name_key, Tablespace>(
    THD *, const Tablespace::Name_key &, enum_tx_isolation, bool,
    const Tablespace **);
template bool Storage_adapter::get<Tablespace::Aux_key, Tablespace>(
    THD *, const Tablespace::Aux_key &, enum_tx_isolation, bool,
    const Tablespace **);
template bool Storage_adapter::drop(THD *, const Tablespace *);
template bool Storage_adapter::store(THD *, Tablespace *);

/*
  DD objects dd::Table_stat and dd::Index_stat are not cached,
  because these objects are only updated and never read by DD
  API's. Information schema system views use these DD tables
  to project table/index statistics. As these objects are
  not in DD cache, it cannot make it to core storage.
*/

template <>
void Storage_adapter::core_get(const Table_stat::Name_key &,
                               const Table_stat **) {}

template <>
void Storage_adapter::core_get(const Index_stat::Name_key &,
                               const Index_stat **) {}

template <>
void Storage_adapter::core_drop(THD *, const Table_stat *) {}

template <>
void Storage_adapter::core_drop(THD *, const Index_stat *) {}

template <>
void Storage_adapter::core_store(THD *, Table_stat *) {}

template <>
void Storage_adapter::core_store(THD *, Index_stat *) {}

template bool Storage_adapter::get<Table_stat::Name_key, Table_stat>(
    THD *, const Table_stat::Name_key &, enum_tx_isolation, bool,
    const Table_stat **);
template bool Storage_adapter::store(THD *, Table_stat *);
template bool Storage_adapter::drop(THD *, const Table_stat *);
template bool Storage_adapter::get<Index_stat::Name_key, Index_stat>(
    THD *, const Index_stat::Name_key &, enum_tx_isolation, bool,
    const Index_stat **);
template bool Storage_adapter::store(THD *, Index_stat *);
template bool Storage_adapter::drop(THD *, const Index_stat *);

// Doxygen doesn't understand this explicit template instantiation.
#ifndef IN_DOXYGEN
template void Storage_adapter::core_drop<Schema>(THD *, const Schema *);
template void Storage_adapter::core_drop<Table>(THD *, const Table *);
template void Storage_adapter::core_drop<Tablespace>(THD *, const Tablespace *);

template void Storage_adapter::core_store<Schema>(THD *, Schema *);
template void Storage_adapter::core_store<Table>(THD *, Table *);
template void Storage_adapter::core_store<Tablespace>(THD *, Tablespace *);
#endif

}  // namespace cache
}  // namespace dd