Skip to content

Commit e38d37a

Browse files
committed
Bug#25840927: ADD WARN_UNUSED_RESULT TO DICTIONARY_CLIENT METHODS
This patch adds MY_ATTRIBUTE((warn_unused_result)) to the declarations of Dictionary_client methods to make the API harder to misuse. Now any API usage that ignores return values will give a compilation warning (GCC, Clang).
1 parent f9f2808 commit e38d37a

File tree

4 files changed

+89
-57
lines changed

4 files changed

+89
-57
lines changed

sql/dd/cache/dictionary_client.h

Lines changed: 55 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <vector>
2323

2424
#include "dd/object_id.h"
25+
#include "my_compiler.h"
2526
#include "my_dbug.h"
2627
#include "object_registry.h" // Object_registry
2728

@@ -257,7 +258,8 @@ class Dictionary_client
257258

258259
template <typename K, typename T>
259260
bool acquire(const K &key, const T **object,
260-
bool *local_committed, bool *local_uncommitted);
261+
bool *local_committed, bool *local_uncommitted)
262+
MY_ATTRIBUTE((warn_unused_result));
261263

262264

263265
/**
@@ -461,7 +463,8 @@ class Dictionary_client
461463
*/
462464

463465
template <typename T>
464-
bool acquire(Object_id id, const T** object);
466+
bool acquire(Object_id id, const T** object)
467+
MY_ATTRIBUTE((warn_unused_result));
465468

466469

467470
/**
@@ -478,7 +481,8 @@ class Dictionary_client
478481
*/
479482

480483
template <typename T>
481-
bool acquire_for_modification(Object_id id, T** object);
484+
bool acquire_for_modification(Object_id id, T** object)
485+
MY_ATTRIBUTE((warn_unused_result));
482486

483487

484488
/**
@@ -498,7 +502,8 @@ class Dictionary_client
498502
*/
499503

500504
template <typename T>
501-
bool acquire_uncached(Object_id id, T** object);
505+
bool acquire_uncached(Object_id id, T** object)
506+
MY_ATTRIBUTE((warn_unused_result));
502507

503508

504509
/**
@@ -522,7 +527,8 @@ class Dictionary_client
522527
*/
523528

524529
template <typename T>
525-
bool acquire_uncached_uncommitted(Object_id id, T** object);
530+
bool acquire_uncached_uncommitted(Object_id id, T** object)
531+
MY_ATTRIBUTE((warn_unused_result));
526532

527533

528534
/**
@@ -537,7 +543,8 @@ class Dictionary_client
537543
*/
538544

539545
template <typename T>
540-
bool acquire(const String_type &object_name, const T** object);
546+
bool acquire(const String_type &object_name, const T** object)
547+
MY_ATTRIBUTE((warn_unused_result));
541548

542549

543550
/**
@@ -554,7 +561,8 @@ class Dictionary_client
554561
*/
555562

556563
template <typename T>
557-
bool acquire_for_modification(const String_type &object_name, T** object);
564+
bool acquire_for_modification(const String_type &object_name, T** object)
565+
MY_ATTRIBUTE((warn_unused_result));
558566

559567

560568
/**
@@ -581,7 +589,8 @@ class Dictionary_client
581589

582590
template <typename T>
583591
bool acquire(const String_type &schema_name, const String_type &object_name,
584-
const T** object);
592+
const T** object)
593+
MY_ATTRIBUTE((warn_unused_result));
585594

586595

587596
/**
@@ -611,7 +620,8 @@ class Dictionary_client
611620
template <typename T>
612621
bool acquire_for_modification(const String_type &schema_name,
613622
const String_type &object_name,
614-
T** object);
623+
T** object)
624+
MY_ATTRIBUTE((warn_unused_result));
615625

616626

617627
/**
@@ -644,7 +654,8 @@ class Dictionary_client
644654

645655
template <typename T>
646656
bool acquire(const String_type &schema_name, const String_type &object_name,
647-
const typename T::cache_partition_type** object);
657+
const typename T::cache_partition_type** object)
658+
MY_ATTRIBUTE((warn_unused_result));
648659

649660

650661
/**
@@ -680,7 +691,8 @@ class Dictionary_client
680691
template <typename T>
681692
bool acquire_for_modification(const String_type &schema_name,
682693
const String_type &object_name,
683-
typename T::cache_partition_type** object);
694+
typename T::cache_partition_type** object)
695+
MY_ATTRIBUTE((warn_unused_result));
684696

685697

686698
/**
@@ -702,7 +714,8 @@ class Dictionary_client
702714

703715
bool acquire_uncached_table_by_se_private_id(const String_type &engine,
704716
Object_id se_private_id,
705-
Table **table);
717+
Table **table)
718+
MY_ATTRIBUTE((warn_unused_result));
706719

707720

708721
/**
@@ -719,7 +732,8 @@ class Dictionary_client
719732
bool acquire_uncached_table_by_partition_se_private_id(
720733
const String_type &engine,
721734
Object_id se_partition_id,
722-
Table **table);
735+
Table **table)
736+
MY_ATTRIBUTE((warn_unused_result));
723737

724738

725739
/**
@@ -739,7 +753,8 @@ class Dictionary_client
739753
bool get_table_name_by_se_private_id(const String_type &engine,
740754
Object_id se_private_id,
741755
String_type *schema_name,
742-
String_type *table_name);
756+
String_type *table_name)
757+
MY_ATTRIBUTE((warn_unused_result));
743758

744759

745760
/**
@@ -759,7 +774,8 @@ class Dictionary_client
759774
bool get_table_name_by_partition_se_private_id(const String_type &engine,
760775
Object_id se_partition_id,
761776
String_type *schema_name,
762-
String_type *table_name);
777+
String_type *table_name)
778+
MY_ATTRIBUTE((warn_unused_result));
763779

764780

765781
/**
@@ -777,7 +793,8 @@ class Dictionary_client
777793

778794
bool get_table_name_by_trigger_name(const Schema &schema,
779795
const String_type &trigger_name,
780-
String_type *table_name);
796+
String_type *table_name)
797+
MY_ATTRIBUTE((warn_unused_result));
781798

782799

783800
/**
@@ -791,7 +808,8 @@ class Dictionary_client
791808
*/
792809

793810
bool get_tables_max_se_private_id(const String_type &engine,
794-
Object_id *max_id);
811+
Object_id *max_id)
812+
MY_ATTRIBUTE((warn_unused_result));
795813

796814

797815
/**
@@ -810,9 +828,9 @@ class Dictionary_client
810828
*/
811829

812830
template <typename T>
813-
bool fetch_schema_component_names(
814-
const Schema *schema,
815-
std::vector<String_type> *names) const;
831+
bool fetch_schema_component_names(const Schema *schema,
832+
std::vector<String_type> *names) const
833+
MY_ATTRIBUTE((warn_unused_result));
816834

817835

818836
/**
@@ -827,9 +845,9 @@ class Dictionary_client
827845
*/
828846

829847
template <typename T>
830-
bool fetch_schema_components(
831-
const Schema *schema,
832-
std::vector<const T*> *coll) const;
848+
bool fetch_schema_components(const Schema *schema,
849+
std::vector<const T*> *coll) const
850+
MY_ATTRIBUTE((warn_unused_result));
833851

834852

835853
/**
@@ -843,7 +861,8 @@ class Dictionary_client
843861
*/
844862

845863
template <typename T>
846-
bool fetch_global_components(std::vector<const T*> *coll) const;
864+
bool fetch_global_components(std::vector<const T*> *coll) const
865+
MY_ATTRIBUTE((warn_unused_result));
847866

848867

849868
/**
@@ -863,10 +882,10 @@ class Dictionary_client
863882
@return false Success.
864883
*/
865884
template <typename T>
866-
bool fetch_referencing_views_object_id(
867-
const char *schema,
868-
const char *tbl_or_sf_name,
869-
std::vector<Object_id> *view_ids) const;
885+
bool fetch_referencing_views_object_id(const char *schema,
886+
const char *tbl_or_sf_name,
887+
std::vector<Object_id> *view_ids) const
888+
MY_ATTRIBUTE((warn_unused_result));
870889

871890

872891
/**
@@ -910,7 +929,8 @@ class Dictionary_client
910929
*/
911930

912931
template <typename T>
913-
bool drop(const T *object);
932+
bool drop(const T *object)
933+
MY_ATTRIBUTE((warn_unused_result));
914934

915935

916936
/**
@@ -939,7 +959,8 @@ class Dictionary_client
939959
*/
940960

941961
template <typename T>
942-
bool store(T* object);
962+
bool store(T* object)
963+
MY_ATTRIBUTE((warn_unused_result));
943964

944965

945966
/**
@@ -968,7 +989,8 @@ class Dictionary_client
968989
*/
969990

970991
template <typename T>
971-
bool update(T* new_object);
992+
bool update(T* new_object)
993+
MY_ATTRIBUTE((warn_unused_result));
972994

973995

974996
/**
@@ -1007,7 +1029,8 @@ class Dictionary_client
10071029
@return false - on success
10081030
*/
10091031
bool remove_table_dynamic_statistics(const String_type &schema_name,
1010-
const String_type &table_name);
1032+
const String_type &table_name)
1033+
MY_ATTRIBUTE((warn_unused_result));
10111034

10121035

10131036
/**

sql/dd/dictionary.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define DD__DICTIONARY_INCLUDED
1818

1919

20+
#include "my_compiler.h"
2021
#include "dd/string_type.h" // dd::String_type
2122

2223
class THD;
@@ -163,7 +164,8 @@ bool acquire_shared_table_mdl(THD *thd,
163164
const char *schema_name,
164165
const char *table_name,
165166
bool no_wait,
166-
MDL_ticket **out_mdl_ticket);
167+
MDL_ticket **out_mdl_ticket)
168+
MY_ATTRIBUTE((warn_unused_result));
167169

168170

169171
/**
@@ -216,7 +218,8 @@ bool has_exclusive_table_mdl(THD *thd,
216218

217219
bool acquire_exclusive_tablespace_mdl(THD *thd,
218220
const char *tablespace_name,
219-
bool no_wait);
221+
bool no_wait)
222+
MY_ATTRIBUTE((warn_unused_result));
220223

221224

222225
/**
@@ -234,7 +237,8 @@ bool acquire_exclusive_tablespace_mdl(THD *thd,
234237
*/
235238
bool acquire_shared_tablespace_mdl(THD *thd,
236239
const char *tablespace_name,
237-
bool no_wait);
240+
bool no_wait)
241+
MY_ATTRIBUTE((warn_unused_result));
238242

239243

240244
/**
@@ -285,7 +289,8 @@ bool acquire_exclusive_table_mdl(THD *thd,
285289
const char *schema_name,
286290
const char *table_name,
287291
bool no_wait,
288-
MDL_ticket **out_mdl_ticket);
292+
MDL_ticket **out_mdl_ticket)
293+
MY_ATTRIBUTE((warn_unused_result));
289294

290295

291296
/**
@@ -304,7 +309,8 @@ bool acquire_exclusive_table_mdl(THD *thd,
304309
bool acquire_exclusive_schema_mdl(THD *thd,
305310
const char *schema_name,
306311
bool no_wait,
307-
MDL_ticket **out_mdl_ticket);
312+
MDL_ticket **out_mdl_ticket)
313+
MY_ATTRIBUTE((warn_unused_result));
308314

309315
/**
310316
@brief

sql/sql_table.cc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10373,20 +10373,23 @@ static bool mysql_inplace_alter_table(THD *thd,
1037310373
rollback:
1037410374
{
1037510375
dd::cache::Dictionary_client::Auto_releaser releaser(thd->dd_client());
10376-
const dd::Table *old_table_def;
10377-
thd->dd_client()->acquire<dd::Table>(table->s->db.str,
10378-
table->s->table_name.str,
10379-
&old_table_def);
10380-
dd::Table *altered_table_def;
10381-
thd->dd_client()->acquire_for_modification<dd::Table>(alter_ctx->new_db,
10382-
alter_ctx->tmp_name,
10383-
&altered_table_def);
10384-
10385-
table->file->ha_commit_inplace_alter_table(altered_table,
10386-
ha_alter_info,
10387-
false, old_table_def,
10388-
altered_table_def);
10389-
thd->check_for_truncated_fields= CHECK_FIELD_IGNORE;
10376+
const dd::Table *old_table_def= nullptr;
10377+
dd::Table *altered_table_def= nullptr;
10378+
if (!thd->dd_client()->acquire(table->s->db.str,
10379+
table->s->table_name.str,
10380+
&old_table_def) &&
10381+
!thd->dd_client()->acquire_for_modification(alter_ctx->new_db,
10382+
alter_ctx->tmp_name,
10383+
&altered_table_def))
10384+
{
10385+
DBUG_ASSERT(old_table_def != nullptr && altered_table_def != nullptr);
10386+
10387+
table->file->ha_commit_inplace_alter_table(altered_table,
10388+
ha_alter_info,
10389+
false, old_table_def,
10390+
altered_table_def);
10391+
thd->check_for_truncated_fields= CHECK_FIELD_IGNORE;
10392+
}
1039010393
}
1039110394

1039210395
cleanup:

0 commit comments

Comments
 (0)