Bug #107715 Multiple SE clone not calling clone_end after mixed clone_begin failure/success
Submitted: 30 Jun 2022 14:07 Modified: 20 Apr 2023 7:36
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Clone Plugin Severity:S2 (Serious)
Version:8.0.29-8.0.32 OS:Any
Assigned to: CPU Architecture:Any
Tags: Clone

[30 Jun 2022 14:07] Laurynas Biveinis
Description:
Suppose there are two clone-supporting storage engines, and that clone_begin succeeds in the first one, but fails in the second one. This results in clone_end not being called for the first storage engine, leaking the clone resources, and, in the case of InnoDB, hitting asserts in Clone_Sys destructor on shutdown.

Both remote and local clones are affected through different code paths. For remote clone, clone_hton.cc hton_clone_begin failing in 2nd or later SE will result in locator and task vectors containing only successful SE data - which is correct - but the caller will keep m_storage_initialized == false, skipping any hton_clone_end calls. For local clone, clone_hton.cc run_hton_clone_begin locator and task vectors are pre-populated, and a failure in the middle will result in them being half-initialized, with no indication which ones actually are initialized.

Note that clone_begin failing is not limited to actual errors happening during clone startup: in the case of clone using multiple threads some of them might be attempting to add tasks late, after the clone has already finished. Thus it is possible to hit this during regular successful clone.

How to repeat:
Code analysis

Suggested fix:
One option is to rollback the successfuly-initialized SEs in both hton_clone_begin and run_hton_clone_begin in the case of error.
[1 Jul 2022 6:43] MySQL Verification Team
Hello Laurynas,

Thank you for the report and feedback!

regards,
Umesh
[4 Jul 2022 8:51] Debarun Banerjee
Posted by developer:
 
Clone with Multiple SEs is not supported yet. The code present is to help future development.
[7 Sep 2022 12:55] Laurynas Biveinis
Bug 107715 fix for 8.0.30

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: bug107715.patch (application/octet-stream, text), 2.17 KiB.

[12 Oct 2022 12:14] Laurynas Biveinis
The patch applies to 8.0.31 too, MTR clone suite passes cleanly.
[17 Jan 2023 14:03] Laurynas Biveinis
Applies cleanly on 8.0.32 and does not regress MTR
[20 Apr 2023 7:36] Laurynas Biveinis
Applies cleanly on 8.0.33 and does not regress MTR