Bug #109919 Clone plugin does not support arbitrary length O_DIRECT files
Submitted: 3 Feb 2023 13:23 Modified: 22 Oct 8:25
Reporter: Laurynas Biveinis (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Clone Plugin Severity:S4 (Feature request)
Version:8.0.32 OS:Linux
Assigned to: CPU Architecture:Any
Tags: Clone, Contribution

[3 Feb 2023 13:23] Laurynas Biveinis
Description:
The clone plugin assumes that any files read or written with O_DIRECT have sizes that are multiples of O_DIRECT block size. This is true for InnoDB, but, in general, O_DIRECT-accessed files can be of any size, because:
- they can be written with the last block padded and then ftruncated to arbitrary size;
- they can be read directly and the last read call will return the actual length of the last file block.

Some other storage engines do use O_DIRECT with arbitrarily-sized files.

How to repeat:
1) Implement clone support for another O_DIRECT-using storage engine with arbitrarily-sized files
2) Clone and observe:

mysqltest: At line 143: Query 'CLONE INSTANCE FROM $USER@$HOST:$PORT IDENTIFIED BY '' $remote_dir_clause' failed.
ERROR 3862 (HY000): Clone Donor Error: 1024 : Error reading file '000043.sst' (errno: 22 - Invalid argument).

Suggested fix:
A possible but not necessary the best fix is

Add a flag to Ha_clone_file to support arbitrary file lengths under O_DIRECT:
o_direct_uneven_file_size. Pass it to clone_client.h/cc
Client::get_aligned_buffer to allocate the buffer that bumps the length to the
next CLONE_OS_ALIGN multiple if it's not already one. Introduce a
pad_for_o_direct helper that performs this calculation for the passed length as
needed.

For writes, if O_DIRECT is enabled and the buffer length is not a multiple of
CLONE_OS_ALIGN, pad it with zeros to the next multiple. Then check the actual
bytes written, and if any padding bytes were actually written, call my_chsize to
truncate the file to the needed size.
[3 Feb 2023 13:25] Laurynas Biveinis
Bug 109919 fix option

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

Contribution: bug109919-poc.patch (application/octet-stream, text), 9.14 KiB.

[6 Feb 2023 4:55] MySQL Verification Team
Hello Laurynas,

Thank you for the feature request and contribution!

regards,
Umesh
[9 Jul 12:58] Laurynas Biveinis
My contributed patch applies cleanly on 9.0.0 and passes the tests.
[22 Oct 8:25] Laurynas Biveinis
The contributed patch applies on 9.1.0 cleanly and passes the tests.