mysql-handler 0.2.0

Rust bindings for the MySQL handler
Documentation
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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
// Copyright (C) 2026 ren-yamanashi
//
// 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 this program 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 for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, see <https://www.gnu.org/licenses/>.

//! Engine-level handlerton interface.
//!
//! Where [`StorageEngine`](crate::engine::StorageEngine) is per-table, the
//! handlerton is a per-engine singleton: one instance serves every connection.
//! An engine opts into engine-level behaviour by implementing [`Handlerton`]
//! and registering it with
//! [`register_handlerton`](crate::runtime::register_handlerton). Engines that
//! need nothing beyond table handling skip registration and keep the
//! zero-config defaults.

#[doc(hidden)]
pub mod binlog;
mod binlog_kind;
mod capabilities;
#[doc(hidden)]
pub mod capability_ffi;
#[doc(hidden)]
pub mod clone;
mod clone_kind;
mod cost_constants;
#[doc(hidden)]
pub mod database;
#[doc(hidden)]
pub mod dict;
mod dict_kind;
#[doc(hidden)]
pub mod discovery;
#[doc(hidden)]
pub mod engine_log;
#[doc(hidden)]
pub mod ffi;
#[doc(hidden)]
pub mod fk_hooks;
mod flags;
#[doc(hidden)]
pub mod lifecycle;
#[doc(hidden)]
pub mod misc_optimizer;
#[doc(hidden)]
pub mod misc_stats;
mod notification_kind;
#[doc(hidden)]
pub mod notifications;
#[doc(hidden)]
pub mod page_track;
mod panic_function;
mod recover_xa_state;
mod result;
#[doc(hidden)]
pub mod savepoint_ffi;
#[doc(hidden)]
pub mod sdi;
#[doc(hidden)]
pub mod secondary_engine;
#[doc(hidden)]
pub mod secondary_engine_fail_reason;
mod secondary_engine_kind;
mod stat_print_sink;
mod stat_type;
#[doc(hidden)]
pub mod statistics_callbacks;
#[doc(hidden)]
pub mod status;
mod table_statistics;
#[doc(hidden)]
pub mod tablespace;
mod tablespace_kind;
mod tablespace_statistics;
mod transaction;
#[doc(hidden)]
pub mod txn_context;
#[doc(hidden)]
pub mod txn_ffi;
#[doc(hidden)]
pub mod txn_row_ffi;
#[doc(hidden)]
pub mod xa;
mod xa_recover_collector;
mod xa_state_list_collector;

pub use binlog_kind::{BinlogCommand, BinlogFunc};
pub use capabilities::HtonCapabilities;
pub use clone_kind::{HaCloneMode, HaCloneType};
pub use cost_constants::CostConstants;
pub use dict_kind::{DictInitMode, DictRecoveryMode};
pub use flags::HtonFlags;
pub use notification_kind::{HaNotificationType, SelectExecutedIn};
pub use panic_function::HaPanicFunction;
pub use recover_xa_state::RecoverXaState;
pub use secondary_engine_kind::{
    SecondaryEngineGraphSimplificationRequest, SecondaryEngineOptimizerRequest,
};
pub use stat_print_sink::StatPrintSink;
pub use stat_type::HaStatType;
pub use table_statistics::TableStatistics;
pub use tablespace_kind::{TablespaceType, TsCommandType};
pub use tablespace_statistics::TablespaceStatistics;
pub use transaction::TxnSession;
pub use xa_recover_collector::XaRecoverCollector;
pub use xa_state_list_collector::XaStateListCollector;

use crate::engine::EngineResult;
use crate::sys;

/// The engine-level handlerton interface: the capabilities and `handlerton`
/// struct fields that apply to the engine as a whole rather than to a single
/// table.
///
/// Every method has a default, so an engine implements only what it needs and
/// an empty `impl Handlerton for MyEngine {}` is a valid handler-only
/// handlerton. The singleton is shared across all connection threads, hence
/// the `Send + Sync` bound — do not relax it.
///
/// # Examples
///
/// ```
/// use mysql_handler::hton::{Handlerton, HtonCapabilities, HtonFlags};
///
/// struct MyHandlerton;
/// impl Handlerton for MyHandlerton {
///     fn capabilities(&self) -> HtonCapabilities {
///         HtonCapabilities::TRANSACTIONS
///     }
/// }
///
/// assert!(MyHandlerton.capabilities().contains(HtonCapabilities::TRANSACTIONS));
/// assert_eq!(MyHandlerton.flags(), HtonFlags::CAN_RECREATE);
/// ```
pub trait Handlerton: Send + Sync {
    /// The engine-level callback groups this handlerton implements.
    ///
    /// Each capability gates a group of `handlerton` callbacks; a group is
    /// wired into MySQL only when its bit is set here. Defaults to
    /// [`HtonCapabilities::empty`] — a handler-only engine.
    fn capabilities(&self) -> HtonCapabilities {
        HtonCapabilities::empty()
    }

    /// The `handlerton` flags (`HTON_*`).
    ///
    /// Defaults to [`HtonFlags::CAN_RECREATE`], matching the flag the
    /// zero-config engine sets today. Return [`HtonFlags::NONE`] to opt out.
    fn flags(&self) -> HtonFlags {
        HtonFlags::CAN_RECREATE
    }

    /// Bytes of per-savepoint scratch the engine needs (`handlerton`'s
    /// `savepoint_offset`). MySQL allocates this much per savepoint and hands it
    /// to the savepoint callbacks as their `sv` buffer. Only consulted when the
    /// engine declares [`HtonCapabilities::SAVEPOINTS`]; defaults to 0.
    fn savepoint_offset(&self) -> u32 {
        0
    }

    /// Called when a connection that has touched this engine closes, so the
    /// engine can release per-connection state.
    ///
    /// MySQL only invokes this for a connection whose `thd->ha_data` slot is
    /// non-empty, so a handler-only engine that never stores per-connection
    /// state does not see it. Defaults to success (nothing to release).
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if releasing the
    /// connection's state fails; MySQL logs it and the connection still closes.
    fn close_connection(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Notification that a connection or its current statement is being
    /// terminated (`KILL`). Defaults to no-op.
    fn kill_connection(&self, _thd: Option<&sys::THD>) {}

    /// Called before the data dictionary shuts down so the engine can stop
    /// background tasks that might still access it. Defaults to no-op.
    fn pre_dd_shutdown(&self) {}

    /// Reset session-scoped plugin variables before the connection ends.
    /// Defaults to no-op.
    fn reset_plugin_vars(&self, _thd: Option<&sys::THD>) {}

    /// Create the per-connection [`TxnSession`] for a new transaction.
    ///
    /// Invoked (through the shim) when a connection first joins a transaction,
    /// but only for an engine that declares
    /// [`HtonCapabilities::TRANSACTIONS`]. The returned session is stored in
    /// the connection's `ha_data` and driven through `commit` / `rollback`
    /// until the transaction ends. The default returns an inert session, so an
    /// engine declaring `TRANSACTIONS` must override this to do real work.
    fn begin_transaction(&self) -> Box<dyn TxnSession> {
        Box::new(NoopTxnSession)
    }

    /// Commit the prepared XA transaction identified by `xid`, found during
    /// recovery. Wired only under [`HtonCapabilities::XA`]; `xid` is opaque
    /// (inspect only the bytes the engine needs). Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default; an XA engine overrides this and errors only on a real failure.
    fn commit_by_xid(&self, xid: Option<&sys::XID>) -> EngineResult {
        let _ = xid;
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Roll back the prepared XA transaction identified by `xid`. Wired only
    /// under [`HtonCapabilities::XA`]. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn rollback_by_xid(&self, xid: Option<&sys::XID>) -> EngineResult {
        let _ = xid;
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Mark the connection's externally-coordinated transactions as prepared in
    /// the server transaction coordinator. Wired only under
    /// [`HtonCapabilities::XA`]. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn set_prepared_in_tc(&self, thd: Option<&sys::THD>) -> EngineResult {
        let _ = thd;
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Mark the prepared XA transaction identified by `xid` as prepared in the
    /// server transaction coordinator. Wired only under
    /// [`HtonCapabilities::XA`]. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn set_prepared_in_tc_by_xid(&self, xid: Option<&sys::XID>) -> EngineResult {
        let _ = xid;
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Report every externally-coordinated XA transaction the engine considers
    /// prepared, along with its [`RecoverXaState`]. Push each entry into
    /// `collector`; the shim forwards them to MySQL's `Xa_state_list::add`.
    /// Wired only under [`HtonCapabilities::XA`]; the default reports nothing.
    ///
    /// The receiver is `&self` to match the other handlerton accessors;
    /// engines that mutate state during recovery should use interior
    /// mutability (e.g. a `Mutex`).
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the engine
    /// cannot enumerate its prepared transactions.
    fn recover_prepared_in_tc(&self, collector: &mut XaStateListCollector) -> EngineResult {
        let _ = collector;
        Ok(())
    }

    /// Recover every prepared XA transaction the engine knows about. Push
    /// each one into `collector` up to its `capacity`; the shim writes
    /// each pushed entry into MySQL's `XA_recover_txn[]` array. Returning
    /// from this method, the shim hands `collector.filled()` back to
    /// MySQL as the recovered-transaction count.
    ///
    /// Wired only under [`HtonCapabilities::XA`]; the default reports
    /// nothing recovered, matching the previous NULL handlerton pointer.
    fn recover(&self, collector: &mut XaRecoverCollector) {
        let _ = collector;
    }

    /// Shutdown notification: the server is invoking `ha_panic` to wind every
    /// engine down. Defaults to success — the engine has nothing to flush on
    /// process exit.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the engine
    /// fails to shut down cleanly; MySQL logs it and continues stopping.
    fn panic(&self, flag: HaPanicFunction) -> EngineResult {
        let _ = flag;
        Ok(())
    }

    /// Start a consistent-snapshot read for the connection, as requested by
    /// `START TRANSACTION WITH CONSISTENT SNAPSHOT`. Wired only when the engine
    /// declares [`HtonCapabilities::TRANSACTIONS`]; defaults to success (the
    /// engine has no snapshot semantics to install).
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the snapshot
    /// cannot be set up.
    fn start_consistent_snapshot(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Flush durable state to disk. `binlog_group_flush` is true when the
    /// invocation comes from the binary log group-commit flush stage, false
    /// from `FLUSH LOGS` or shutdown. Defaults to success (nothing to flush).
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the flush
    /// fails; MySQL reports the failure to the client.
    fn flush_logs(&self, _binlog_group_flush: bool) -> EngineResult {
        Ok(())
    }

    /// Populate `SHOW ENGINE <name> STATUS` / `LOGS` / `MUTEX` output by
    /// emitting rows through `sink`. The trait default emits no rows, leaving
    /// the engine status empty.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if collecting or
    /// emitting status fails.
    fn show_status(
        &self,
        _thd: Option<&sys::THD>,
        _sink: &StatPrintSink<'_>,
        _stat: HaStatType,
    ) -> EngineResult {
        Ok(())
    }

    /// Per-partition capability bitfield (`HA_*_PARTITION_*` flags from
    /// `sql_partition.h`). Consulted only when the engine declares
    /// [`HtonCapabilities::PARTITIONING`]; defaults to 0 — no special
    /// partitioning behaviour.
    fn partition_flags(&self) -> u32 {
        0
    }

    /// Fill engine-defined rows of an `INFORMATION_SCHEMA` table. The default
    /// adds no rows, which is correct for an engine with no engine-only I_S
    /// surface.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if collecting
    /// rows fails.
    fn fill_is_table(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Roll the engine's log files forward as part of an in-place server
    /// upgrade. Defaults to success — the engine has no upgrade-specific log
    /// work to do.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the upgrade
    /// step fails; MySQL aborts the upgrade.
    fn upgrade_logs(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Finalize upgrade-specific state, called regardless of whether the
    /// upgrade succeeded. `failed_upgrade` is true when MySQL rolled back the
    /// upgrade. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the cleanup
    /// step fails.
    fn finish_upgrade(&self, _thd: Option<&sys::THD>, _failed_upgrade: bool) -> EngineResult {
        Ok(())
    }

    /// Whether the supplied database name is reserved by the engine and must
    /// not be created at the SQL layer. Defaults to `false` — the engine
    /// reserves no names.
    fn is_reserved_db_name(&self, _name: &str) -> bool {
        false
    }

    /// Recover a table whose dictionary entry is missing by reading the
    /// engine-side description back into `db.name`. Defaults to "not found"
    /// (the trait returns `Unsupported`, which the shim translates to
    /// `HA_ERR_NO_SUCH_TABLE`).
    ///
    /// The shim does not yet marshal the engine's SDI blob back through the
    /// `frmblob` / `frmlen` output parameters, so overriding this to return
    /// `Ok(())` would claim "found" without supplying the table definition and
    /// MySQL would fail downstream with `ER_NO_SUCH_TABLE` anyway. Keep the
    /// default until that return path is wired.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default to report "no such table".
    fn discover(&self, _thd: Option<&sys::THD>, _db: &str, _name: &str) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// List the tables (or directory entries) the engine knows about under
    /// `db` / `path`. `wild` is an optional shell-style filter; `dir` is true
    /// when MySQL is asking for sub-directories. Defaults to success with no
    /// entries reported.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if enumeration
    /// fails.
    fn find_files(
        &self,
        _thd: Option<&sys::THD>,
        _db: &str,
        _path: &str,
        _wild: Option<&str>,
        _dir: bool,
    ) -> EngineResult {
        Ok(())
    }

    /// Whether `db.name` exists in the engine. The handler.cc caller maps
    /// `true` to `HA_ERR_TABLE_EXIST` and `false` to `HA_ERR_NO_SUCH_TABLE`,
    /// so the default `false` matches "engine has no such table".
    fn table_exists_in_engine(&self, _thd: Option<&sys::THD>, _db: &str, _name: &str) -> bool {
        false
    }

    /// Whether `db.table_name` is a system table this engine supports.
    /// `is_sql_layer_system_table` is `true` when the table is an SQL-layer
    /// system table (such as `mysql.*`); the engine should answer `false`
    /// unless it specifically supports those at the engine layer. Defaults to
    /// `false` — the engine supports no system tables.
    fn is_supported_system_table(
        &self,
        _db: &str,
        _table_name: &str,
        _is_sql_layer_system_table: bool,
    ) -> bool {
        false
    }

    /// Notification fired after a `SELECT` completed, with the engine that
    /// actually executed it. Defaults to no-op.
    fn notify_after_select(&self, _thd: Option<&sys::THD>, _executed_in: SelectExecutedIn) {}

    /// Notification fired when a table is created, with the bare `db` /
    /// `table_name` strings. The `HA_CREATE_INFO` parameter is opaque to Rust
    /// today and is not surfaced. Defaults to no-op.
    fn notify_create_table(&self, _db: &str, _table_name: &str) {}

    /// Notification fired when a table is dropped. The `Table_ref` parameter
    /// is opaque to Rust and is not surfaced. Defaults to no-op.
    fn notify_drop_table(&self) {}

    /// Pre/post notification around an exclusive metadata lock acquisition.
    /// Returning an error from the pre-event hook tells MySQL to abort
    /// acquisition (the shim translates `Err` to `true`, matching MySQL's
    /// "failure" convention). Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) to veto the
    /// pre-event lock acquisition. Returning `Err` from a post-event
    /// notification is logged by MySQL but does not undo the lock.
    fn notify_exclusive_mdl(
        &self,
        _thd: Option<&sys::THD>,
        _mdl_key: Option<&sys::MdlKey>,
        _kind: HaNotificationType,
    ) -> EngineResult {
        Ok(())
    }

    /// Pre/post notification around an `ALTER TABLE`. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) to veto a
    /// pre-event alter.
    fn notify_alter_table(
        &self,
        _thd: Option<&sys::THD>,
        _mdl_key: Option<&sys::MdlKey>,
        _kind: HaNotificationType,
    ) -> EngineResult {
        Ok(())
    }

    /// Pre/post notification around a `RENAME TABLE`. The old / new
    /// db.table names are passed as borrowed `&str`. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) to veto a
    /// pre-event rename.
    #[allow(clippy::too_many_arguments)]
    fn notify_rename_table(
        &self,
        _thd: Option<&sys::THD>,
        _mdl_key: Option<&sys::MdlKey>,
        _kind: HaNotificationType,
        _old_db: &str,
        _old_name: &str,
        _new_db: &str,
        _new_name: &str,
    ) -> EngineResult {
        Ok(())
    }

    /// Pre/post notification around a `TRUNCATE TABLE`. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) to veto a
    /// pre-event truncate.
    fn notify_truncate_table(
        &self,
        _thd: Option<&sys::THD>,
        _mdl_key: Option<&sys::MdlKey>,
        _kind: HaNotificationType,
    ) -> EngineResult {
        Ok(())
    }

    /// Binlog-related operation MySQL is asking the engine to handle
    /// (`BFN_*`). Defaults to success (engine is binlog-agnostic).
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the operation
    /// fails.
    fn binlog_func(&self, _thd: Option<&sys::THD>, _func: BinlogFunc) -> EngineResult {
        Ok(())
    }

    /// Notification of a DDL command being written to the binary log. The
    /// `query` text is bounded; per the security rule the trait must not log
    /// it. Defaults to no-op.
    fn binlog_log_query(
        &self,
        _thd: Option<&sys::THD>,
        _command: BinlogCommand,
        _query: &str,
        _db: &str,
        _table: &str,
    ) {
    }

    /// Notification of an ACL change (`GRANT` / `REVOKE` / privilege table
    /// modification). The `Acl_change_notification` parameter is opaque to
    /// Rust today and is not surfaced. Defaults to no-op.
    fn acl_notify(&self, _thd: Option<&sys::THD>) {}

    /// Notification of `DROP DATABASE`. `path` is the schema's storage path
    /// (typically `./<dbname>`). Always wired on a registered handlerton.
    /// Defaults to no-op.
    fn drop_database(&self, _path: &str) {}

    /// Whether `tablespace_name` is acceptable for the given DDL command. Wired
    /// only under [`HtonCapabilities::TABLESPACES`]; defaults to `true` so the
    /// engine does not reject names for an unrelated reason.
    fn is_valid_tablespace_name(&self, _cmd: TsCommandType, _tablespace_name: &str) -> bool {
        true
    }

    /// Look up the tablespace name that holds `db.table_name`. The current
    /// binding does not yet round-trip the output back to MySQL — the shim
    /// leaves the `LEX_CSTRING*` empty — so an override returning `Ok(())` is
    /// equivalent to "no tablespace information available".
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on lookup
    /// failure.
    fn get_tablespace(
        &self,
        _thd: Option<&sys::THD>,
        _db_name: &str,
        _table_name: &str,
    ) -> EngineResult {
        Ok(())
    }

    /// Apply a tablespace DDL (`CREATE TABLESPACE`, `ALTER TABLESPACE`, ...).
    /// `ts_info` is opaque today. Wired only under
    /// [`HtonCapabilities::TABLESPACES`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the DDL fails.
    fn alter_tablespace(
        &self,
        _thd: Option<&sys::THD>,
        _ts_info: Option<&sys::StAlterTablespace>,
    ) -> EngineResult {
        Ok(())
    }

    /// Default file-extension MySQL appends to tablespace data files. Wired
    /// only under [`HtonCapabilities::TABLESPACES`]; default `None` produces a
    /// NULL pointer at the C boundary (no extension).
    fn tablespace_filename_ext(&self) -> Option<&'static core::ffi::CStr> {
        None
    }

    /// Upgrade tablespace-level state from a previous server version.
    /// Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the upgrade
    /// step fails.
    fn upgrade_tablespace(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Upgrade the on-disk version of `tablespace`. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the upgrade
    /// step fails.
    fn upgrade_space_version(&self, _tablespace: Option<&sys::DdTablespace>) -> EngineResult {
        Ok(())
    }

    /// Classification of the given tablespace. Defaults to `None`, which the
    /// shim reports back to MySQL as failure to determine the type (so MySQL
    /// keeps whatever it already knows).
    fn get_tablespace_type(
        &self,
        _tablespace: Option<&sys::DdTablespace>,
    ) -> Option<TablespaceType> {
        None
    }

    /// Classification of the tablespace identified by `tablespace_name`.
    /// Defaults to `None` (see [`Self::get_tablespace_type`]).
    fn get_tablespace_type_by_name(&self, _tablespace_name: &str) -> Option<TablespaceType> {
        None
    }

    /// Initialise the engine as the data-dictionary backend. The DD-tables /
    /// DD-tablespaces output lists are not surfaced today (they are produced
    /// only by the DD backend). Wired only under
    /// [`HtonCapabilities::DICT_BACKEND`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on init failure.
    fn dict_init(&self, _mode: DictInitMode, _version: u32) -> EngineResult {
        Ok(())
    }

    /// DD-backend variant of [`Self::dict_init`] used by the DDSE-specific
    /// startup path. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on init failure.
    fn ddse_dict_init(&self, _mode: DictInitMode, _version: u32) -> EngineResult {
        Ok(())
    }

    /// Register the hard-coded DD table-id range with the engine. `table_id`
    /// is `dd::Object_id` (a 64-bit integer). Defaults to no-op.
    fn dict_register_dd_table_id(&self, _table_id: u64) {}

    /// Invalidate the engine's local cache entry for `schema.table`.
    /// Defaults to no-op.
    fn dict_cache_reset(&self, _schema_name: &str, _table_name: &str) {}

    /// Invalidate every table and tablespace entry in the engine's local
    /// dictionary cache. Defaults to no-op.
    fn dict_cache_reset_tables_and_tablespaces(&self) {}

    /// Perform engine-side recovery work as part of dictionary initialisation.
    /// Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if recovery
    /// fails.
    fn dict_recover(&self, _mode: DictRecoveryMode, _version: u32) -> EngineResult {
        Ok(())
    }

    /// Read back the server version stored in the dictionary tablespace
    /// header. Defaults to `None`, which the shim reports back as failure.
    fn dict_get_server_version(&self) -> Option<u32> {
        None
    }

    /// Persist the current server version into the dictionary tablespace
    /// header. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on write
    /// failure.
    fn dict_set_server_version(&self) -> EngineResult {
        Ok(())
    }

    /// Create the SDI store for `tablespace`. Wired only under
    /// [`HtonCapabilities::SDI`]; defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn sdi_create(&self, _tablespace: Option<&sys::DdTablespace>) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Drop the SDI store from `tablespace`. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn sdi_drop(&self, _tablespace: Option<&sys::DdTablespace>) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Populate `vector` with the SDI keys present in `tablespace`. The
    /// `sdi_vector_t` output cannot be filled through the opaque
    /// pass-through today; defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn sdi_get_keys(
        &self,
        _tablespace: Option<&sys::DdTablespace>,
        _vector: Option<&sys::SdiVector>,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Look up the SDI payload identified by `key` and write it into `buf`.
    /// On success the engine must set `*len_out` to the bytes actually
    /// written. The shim treats `buf` as a `&mut [u8]` whose length is the
    /// caller-provided capacity. Defaults to unsupported.
    ///
    /// MySQL distinguishes the two error paths by inspecting `*len_out`:
    /// - **Buffer too small** — return an error and set `*len_out` to the
    ///   required payload size so the caller can retry with a larger buffer.
    /// - **Genuine error** (key not found, I/O failure, ...) — return an
    ///   error and set `*len_out = u64::MAX`. Without this sentinel MySQL
    ///   re-enters the call expecting a retry and may loop indefinitely.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default. Engines that store SDI follow the two-path convention
    /// above.
    fn sdi_get(
        &self,
        _tablespace: Option<&sys::DdTablespace>,
        _key: Option<&sys::SdiKey>,
        _buf: &mut [u8],
        _len_out: &mut u64,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Store `payload` as the SDI value for `key` against `table` /
    /// `tablespace`. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn sdi_set(
        &self,
        _tablespace: Option<&sys::DdTablespace>,
        _table: Option<&sys::DdTable>,
        _key: Option<&sys::SdiKey>,
        _payload: &[u8],
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Delete the SDI value identified by `key`. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn sdi_delete(
        &self,
        _tablespace: Option<&sys::DdTablespace>,
        _table: Option<&sys::DdTable>,
        _key: Option<&sys::SdiKey>,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Acquire the engine-log mutex so a backup tool can snapshot a
    /// consistent log state. Wired only under
    /// [`HtonCapabilities::ENGINE_LOG`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) when the lock
    /// cannot be taken.
    fn lock_hton_log(&self) -> EngineResult {
        Ok(())
    }

    /// Release the mutex taken by [`Self::lock_hton_log`]. Defaults to
    /// success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on release
    /// failure.
    fn unlock_hton_log(&self) -> EngineResult {
        Ok(())
    }

    /// Append the engine's redo / transaction log status into the
    /// `performance_schema.log_status` collector. The `Json_dom` parameter is
    /// opaque today; an engine with log info will need a reverse callback to
    /// populate the JSON tree. Defaults to no-op success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on collection
    /// failure.
    fn collect_hton_log_info(&self, _json: Option<&sys::JsonDom>) -> EngineResult {
        Ok(())
    }

    /// Whether the engine considers the two foreign-key column type
    /// descriptors compatible (used when MySQL validates an `ADD FOREIGN KEY`
    /// referencing this engine's tables). `Ha_fk_column_type` is opaque
    /// today; the trait default returns `true` (accept any), which matches the
    /// permissive base-engine behaviour. Override to enforce stricter typing.
    fn check_fk_column_compat(
        &self,
        _child: Option<&sys::HaFkColumnType>,
        _parent: Option<&sys::HaFkColumnType>,
        _check_charsets: bool,
    ) -> bool {
        true
    }

    /// Plugin-observer hook fired before a transaction commits. The shim
    /// discards the observer's `void*` argument because it belongs to the
    /// observer plugin that registered the hook, not to the storage engine;
    /// engines that need observer data must coordinate with the observer
    /// through a separate channel. Defaults to no-op.
    fn se_before_commit(&self) {}

    /// Plugin-observer hook fired after a transaction commits. See
    /// [`Self::se_before_commit`] for the observer-arg discussion. Defaults
    /// to no-op.
    fn se_after_commit(&self) {}

    /// Plugin-observer hook fired before a transaction rolls back. See
    /// [`Self::se_before_commit`] for the observer-arg discussion. Defaults
    /// to no-op.
    fn se_before_rollback(&self) {}

    /// Prepare the secondary engine for executing a statement. `lex` is
    /// opaque today. Wired only under
    /// [`HtonCapabilities::SECONDARY_ENGINE`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if preparation
    /// fails; MySQL falls back to the primary engine.
    fn prepare_secondary_engine(
        &self,
        _thd: Option<&sys::THD>,
        _lex: Option<&sys::Lex>,
    ) -> EngineResult {
        Ok(())
    }

    /// Optimize a statement for execution on the secondary engine. `lex` is
    /// opaque today. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the
    /// optimization fails; MySQL reprepares for the primary engine.
    fn optimize_secondary_engine(
        &self,
        _thd: Option<&sys::THD>,
        _lex: Option<&sys::Lex>,
    ) -> EngineResult {
        Ok(())
    }

    /// Compare the cost of `join` against the best plan seen so far. The
    /// trait returns `(use_best_so_far, cheaper, secondary_engine_cost)`;
    /// `None` defaults the triple to `(false, false, optimizer_cost)`, which
    /// the shim writes back to the C `bool*` / `double*` outputs.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on error; the
    /// optimizer drops the candidate plan.
    fn compare_secondary_engine_cost(
        &self,
        _thd: Option<&sys::THD>,
        _join: Option<&sys::Join>,
        _optimizer_cost: f64,
    ) -> EngineResult<Option<(bool, bool, f64)>> {
        Ok(None)
    }

    /// Evaluate (and potentially modify) the cost estimates on `access_path`
    /// from the hypergraph optimizer. `access_path` is opaque to Rust today,
    /// so the default cannot modify costs; returning `Ok(())` accepts the
    /// path unchanged.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) to reject the
    /// access path entirely.
    fn secondary_engine_modify_access_path_cost(
        &self,
        _thd: Option<&sys::THD>,
        _hypergraph: Option<&sys::JoinHypergraph>,
        _access_path: Option<&sys::AccessPath>,
    ) -> EngineResult {
        Ok(())
    }

    /// Whether `EXPLAIN` references tables not loaded into the secondary
    /// engine. Defaults to `false` (all referenced tables are loaded).
    fn external_engine_explain_check(&self, _thd: Option<&sys::THD>) -> bool {
        false
    }

    // `get_secondary_engine_offload_or_exec_fail_reason` and
    // `find_secondary_engine_offload_fail_reason` are wired at the FFI layer
    // but intentionally not surfaced as trait methods today: returning
    // engine-owned bytes by value would drop the buffer before MySQL wrapped
    // it in `std::string_view`, exposing freed heap memory. The FFI returns an
    // empty view until a future setter reverse-callback can hand
    // statement-scoped bytes to MySQL safely. `set_*` below is unaffected.

    /// Persist `reason` as the offload failure reason for the query
    /// represented by `thd`. Defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if the engine
    /// could not record the reason.
    fn set_secondary_engine_offload_fail_reason(
        &self,
        _thd: Option<&sys::THD>,
        _reason: &str,
    ) -> EngineResult {
        Ok(())
    }

    /// Hook the hypergraph optimizer calls after
    /// [`Self::secondary_engine_modify_access_path_cost`] to decide whether
    /// to keep optimizing, restart with a different subgraph budget, etc.
    /// Defaults to [`SecondaryEngineOptimizerRequest::keep_going`]. The
    /// `JoinHypergraph` / `AccessPath` / `trace` parameters are opaque.
    fn secondary_engine_check_optimizer_request(
        &self,
        _thd: Option<&sys::THD>,
        _hypergraph: Option<&sys::JoinHypergraph>,
        _access_path: Option<&sys::AccessPath>,
        _current_subgraph_pairs: i32,
        _current_subgraph_pairs_limit: i32,
        _is_root_access_path: bool,
    ) -> SecondaryEngineOptimizerRequest {
        SecondaryEngineOptimizerRequest::keep_going()
    }

    /// Pre-prepare hook called early in optimization to decide whether the
    /// secondary engine's full prepare path should run. Defaults to `false`
    /// (skip the prepare path), matching the upstream "no further prepare"
    /// signal.
    fn secondary_engine_pre_prepare_hook(&self, _thd: Option<&sys::THD>) -> bool {
        false
    }

    /// Whether the engine's data dictionary is currently read-only. Always
    /// wired on a registered handlerton; defaults to `false`.
    fn is_dict_readonly(&self) -> bool {
        false
    }

    /// Clean up engine-owned temporary tables. The `List<LEX_STRING>*` MySQL
    /// passes in is opaque today and dropped. Always wired; defaults to
    /// success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on cleanup
    /// failure.
    fn rm_tmp_tables(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Ok(())
    }

    /// Provide engine-specific optimizer cost constants for
    /// `storage_category` (raw MySQL `Cost_constants_storage_category` value).
    /// Return [`None`] to keep MySQL's defaults; return [`Some`] to override.
    fn get_cost_constants(&self, _storage_category: u32) -> Option<CostConstants> {
        None
    }

    /// Notification that MySQL is swapping the connection's native engine
    /// transaction. The `void *` / `void **` arguments are opaque to Rust
    /// (observer-style) and are dropped at the FFI boundary. Always wired;
    /// defaults to no-op.
    fn replace_native_transaction_in_thd(&self, _thd: Option<&sys::THD>) {}

    /// Optimizer pushdown at the handlerton layer. The `AccessPath` /
    /// `JOIN` pointers stay opaque (dropped at the FFI boundary today —
    /// the engine sees only the `THD`). The handlerton pointer is wired
    /// unconditionally; MySQL only invokes it after the handler-level
    /// [`crate::engine::StorageEngine::hton_supporting_engine_pushdown`]
    /// reports the engine wants pushdown. The default returns
    /// [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// so an engine that opts into pushdown but forgets to implement
    /// this method gets a loud error instead of silently broken
    /// query results.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) if pushdown
    /// fails or is unsupported.
    fn push_to_engine(&self, _thd: Option<&sys::THD>) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Rotate the encryption master key. Wired only under
    /// [`HtonCapabilities::ENCRYPTION`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on rotation
    /// failure.
    fn rotate_encryption_master_key(&self) -> EngineResult {
        Ok(())
    }

    /// Enable or disable engine redo logging. Wired only under
    /// [`HtonCapabilities::ENGINE_LOG`]; defaults to success.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on toggle
    /// failure.
    fn redo_log_set_state(&self, _thd: Option<&sys::THD>, _enable: bool) -> EngineResult {
        Ok(())
    }

    /// Retrieve engine-published statistics for the (`db_name`, `table_name`)
    /// pair. Return `Ok(Some(stats))` to populate MySQL's `ha_statistics`,
    /// `Ok(None)` when the engine knows nothing about the table, or `Err` on
    /// a real retrieval failure. The shim copies each field of `stats` into
    /// the matching `ha_statistics` slot before returning to MySQL.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on retrieval
    /// failure.
    fn get_table_statistics(
        &self,
        _db_name: &str,
        _table_name: &str,
        _se_private_id: u64,
        _flags: u32,
    ) -> EngineResult<Option<TableStatistics>> {
        Ok(None)
    }

    /// Retrieve the cardinality of a single index column. Same opaque-output
    /// situation as [`Self::get_table_statistics`]; the FFI pointer stays
    /// NULL on the handlerton today.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on retrieval
    /// failure.
    fn get_index_column_cardinality(
        &self,
        _db_name: &str,
        _table_name: &str,
        _index_name: &str,
        _index_ordinal_position: u32,
        _column_ordinal_position: u32,
        _se_private_id: u64,
    ) -> EngineResult<Option<u64>> {
        Ok(None)
    }

    /// Retrieve engine-published statistics for the (`tablespace_name`,
    /// `file_name`) pair. Return `Ok(Some(stats))` to populate MySQL's
    /// `ha_tablespace_statistics`, `Ok(None)` when the engine knows nothing
    /// about the tablespace, or `Err` on a real retrieval failure. Only the
    /// numeric fields cross the FFI boundary today; the five string fields
    /// keep their default-empty values.
    ///
    /// # Errors
    /// Returns an [`EngineError`](crate::engine::EngineError) on retrieval
    /// failure.
    fn get_tablespace_statistics(
        &self,
        _tablespace_name: &str,
        _file_name: &str,
    ) -> EngineResult<Option<TablespaceStatistics>> {
        Ok(None)
    }

    /// Notification fired after a DDL completes. Always wired on a registered
    /// handlerton; defaults to no-op.
    fn post_ddl(&self, _thd: Option<&sys::THD>) {}

    /// Notification fired after server recovery completes. Always wired on a
    /// registered handlerton; defaults to no-op.
    fn post_recover(&self) {}

    /// Report the engine's clone capability bits. Wired only under
    /// [`HtonCapabilities::CLONE`]; defaults to 0 (no clone features
    /// supported). The trait surfaces the bits as a `u64` mirroring
    /// `std::bitset<HA_CLONE_TYPE_MAX>` width on the C side.
    fn clone_capability(&self) -> u64 {
        0
    }

    /// Begin a clone copy on the source engine. The `Ha_clone_cbk` data-
    /// transfer object and the in/out locator parameters are opaque to Rust
    /// today; the trait sees only the high-level request. Defaults to
    /// unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_begin(
        &self,
        _thd: Option<&sys::THD>,
        _clone_type: HaCloneType,
        _mode: HaCloneMode,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Copy a chunk of clone data via the engine-owned callback. Defaults
    /// to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_copy(
        &self,
        _thd: Option<&sys::THD>,
        _task_id: u32,
        _cbk: Option<&sys::HaCloneCbk>,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Acknowledge clone data already transferred. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_ack(
        &self,
        _thd: Option<&sys::THD>,
        _task_id: u32,
        _in_err: i32,
        _cbk: Option<&sys::HaCloneCbk>,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// End a clone copy. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_end(&self, _thd: Option<&sys::THD>, _task_id: u32, _in_err: i32) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Begin applying clone data on the destination engine. `data_dir` is
    /// the target data directory. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_apply_begin(
        &self,
        _thd: Option<&sys::THD>,
        _mode: HaCloneMode,
        _data_dir: &str,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Apply a chunk of clone data via the engine-owned callback. Defaults
    /// to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_apply(
        &self,
        _thd: Option<&sys::THD>,
        _task_id: u32,
        _in_err: i32,
        _cbk: Option<&sys::HaCloneCbk>,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// End a clone apply. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn clone_apply_end(
        &self,
        _thd: Option<&sys::THD>,
        _task_id: u32,
        _in_err: i32,
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Start page tracking. Returns the engine's start ID (LSN-like sequence
    /// number). Wired only under [`HtonCapabilities::PAGE_TRACKING`];
    /// defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn page_track_start(&self) -> EngineResult<u64> {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Stop page tracking. Returns the engine's stop ID. Defaults to
    /// unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn page_track_stop(&self) -> EngineResult<u64> {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Purge page-tracking data up to `purge_id`. Returns the ID actually
    /// purged through. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn page_track_purge(&self, _purge_id: u64) -> EngineResult<u64> {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Fetch tracked page IDs between `start_id` and `stop_id`. The MySQL
    /// `Page_Track_Callback` and its context are opaque to the Rust trait
    /// today (engines that fetch will need a reverse-callback surface).
    /// Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn page_track_get_page_ids(
        &self,
        _start_id: u64,
        _stop_id: u64,
        _buffer: &mut [u8],
    ) -> EngineResult {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Approximate the number of tracked pages between `start_id` and
    /// `stop_id`. Defaults to unsupported.
    ///
    /// # Errors
    /// Returns [`EngineError::Unsupported`](crate::engine::EngineError::Unsupported)
    /// by default.
    fn page_track_get_num_page_ids(&self, _start_id: u64, _stop_id: u64) -> EngineResult<u64> {
        Err(crate::engine::EngineError::Unsupported)
    }

    /// Fetch the page-tracking status. The C signature returns a
    /// `std::vector<std::pair<uint64_t, bool>>` by value; that container
    /// cannot be synthesised through the opaque pass-through today, so the
    /// trait method is bound for completeness and the shim writes an empty
    /// status. Defaults to no-op.
    fn page_track_get_status(&self) {}
}

/// Inert default session returned by [`Handlerton::begin_transaction`] (see
/// there). Accepts and discards transaction boundaries without doing work.
#[derive(Debug)]
struct NoopTxnSession;

impl TxnSession for NoopTxnSession {
    fn commit(&mut self, _all: bool) -> EngineResult {
        Ok(())
    }

    fn rollback(&mut self, _all: bool) -> EngineResult {
        Ok(())
    }
}