Skip to content

Commit c77278b

Browse files
MDEV-39092 BACKUP SERVER of ENGINE=Aria to the local file system
Incorporate changes from code review.
1 parent c143ff2 commit c77278b

8 files changed

Lines changed: 148 additions & 76 deletions

File tree

include/my_backup.h

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,64 @@ this program; if not, write to the Free Software Foundation, Inc.,
1717

1818
#pragma once
1919

20-
#include <cstdint>
20+
#include <stdint.h>
2121

22-
namespace backup
23-
{
22+
#ifndef _WIN32
23+
#include <sys/types.h>
24+
#endif // _WIN32
2425

25-
using target_dir_t= IF_WIN(const char*,int);
2626

27-
inline void* to_void_ptr(target_dir_t tgt) noexcept
28-
{
29-
return IF_WIN(const_cast<char*>, reinterpret_cast<void*>)(tgt);
30-
}
27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
3130

32-
inline target_dir_t to_target_dir(void* ptr) noexcept
33-
{
34-
return IF_WIN(static_cast<const char*>(ptr),
35-
int(reinterpret_cast<uintptr_t>(ptr)));
36-
}
31+
typedef IF_WIN(const char*,int) Backup_target;
3732

3833
#ifndef _WIN32
39-
/** Copy a file.
34+
/** Copy a file in its entirety.
4035
@param src source file descriptor
4136
@param dst target to append src to
4237
@return error code (negative)
4338
@retval 0 on success */
44-
int copy_file(int src, int dst) noexcept;
39+
int my_copy_file_fd(int src, int dst);
4540

46-
/** Copy the entire file.
41+
/** Copy a file given a known length to be copied.
4742
@param src source file descriptor
4843
@param dst target to append src to
4944
@param size amount of data to be copied
5045
@return error code (negative)
5146
@retval 0 on success */
52-
int copy_file(int src, int dst, off_t size) noexcept;
47+
int my_copy_file_length_fd(int src, int dst, off_t size);
48+
5349
#endif // _WIN32
50+
51+
#ifdef __cplusplus
5452
}
53+
namespace backup
54+
{
55+
56+
using Target= Backup_target;
57+
58+
inline void* to_void_ptr(const Target &tgt) noexcept
59+
{
60+
return IF_WIN(const_cast<char*>, reinterpret_cast<void*>)(tgt);
61+
}
62+
63+
inline Target to_target(void* ptr) noexcept
64+
{
65+
return IF_WIN(static_cast<const char*>(ptr),
66+
int(reinterpret_cast<uintptr_t>(ptr)));
67+
}
68+
69+
# ifndef _WIN32
70+
71+
/* Same as my_copy_file_fd but for C++ code. */
72+
int copy_file(int src, int dst) noexcept;
73+
74+
/* Same as for my_copy_file_length_fd but for C++ code. */
75+
int copy_file(int src, int dst, off_t size) noexcept;
76+
77+
# endif // _WIN32
78+
}
79+
80+
#endif // __cplusplus

mysys/my_backup.cc

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,29 @@
1111
# include <sys/mman.h>
1212
#endif
1313

14+
#ifndef _WIN32
15+
/** Copy a file in its entirety.
16+
@param src source file descriptor
17+
@param dst target to append src to
18+
@return error code (negative)
19+
@retval 0 on success */
20+
int my_copy_file_fd(int src, int dst)
21+
{
22+
return backup::copy_file(src, dst);
23+
}
24+
25+
/** Copy a file given a known length to be copied.
26+
@param src source file descriptor
27+
@param dst target to append src to
28+
@param size amount of data to be copied
29+
@return error code (negative)
30+
@retval 0 on success */
31+
int my_copy_file_length_fd(int src, int dst, off_t size)
32+
{
33+
return backup::copy_file(src, dst, size);
34+
}
35+
36+
#endif
1437
namespace
1538
{
1639
#if !(defined __APPLE__ || defined _WIN32)
@@ -44,7 +67,7 @@ copy_step(int in_fd, int out_fd, size_t count, off_t *offset) noexcept
4467
return copy_file_range(in_fd, offset, out_fd, nullptr, count, 0);
4568
}
4669
# define cfr(src,dst,size) copy<copy_step>(src, dst, size)
47-
# endif
70+
# endif // defined __linux__ || defined __FreeBSD__
4871
# ifdef __linux__
4972
/* Copy a file to a stream or to a regular file. */
5073
static inline ssize_t
@@ -62,10 +85,10 @@ send_step(int in_fd, int out_fd, size_t count, off_t *offset) noexcept
6285
@retval 1 if a memory mapping failed */
6386
static ssize_t mmap_copy(int in_fd, int out_fd, off_t count)
6487
{
65-
#if SIZEOF_SIZE_T < 8
88+
# if SIZEOF_SIZE_T < 8
6689
if (count != ssize_t(count))
6790
return 1;
68-
#endif
91+
# endif // SIZEOF_SIZE_T < 8
6992
void *p= mmap(nullptr, count, PROT_READ, MAP_SHARED, in_fd, 0);
7093
if (p == MAP_FAILED)
7194
return 1;
@@ -121,56 +144,46 @@ static ssize_t pread_write(int in_fd, int out_fd, off_t count) noexcept
121144
aligned_free(b);
122145
return ret;
123146
}
124-
# endif
125-
#endif
147+
# endif // __linux__
148+
#endif // !(defined __APPLE__ || defined _WIN32)
126149
}
127150

128151
namespace backup
129152
{
130153

131154
#ifndef _WIN32
132-
/** Copy a file.
133-
@param src source file descriptor
134-
@param dst target to append src to
135-
@return error code (negative)
136-
@retval 0 on success */
155+
137156
int copy_file(int src, int dst) noexcept
138157
{
139-
#ifdef __APPLE__
158+
# ifdef __APPLE__
140159
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
141-
#else
160+
# else
142161
return copy_file(src, dst, lseek(src, 0, SEEK_END));
143-
#endif
162+
# endif // __APPLE__
144163
}
145164

146-
/** Copy a file.
147-
@param src source file descriptor
148-
@param dst target to append src to
149-
@param size amount of data to be copied
150-
@return error code (negative)
151-
@retval 0 on success */
152165
int copy_file(int src, int dst, off_t size) noexcept
153166
{
154-
#ifdef __APPLE__
167+
# ifdef __APPLE__
155168
return fcopyfile(src, dst, nullptr, COPYFILE_ALL | COPYFILE_CLONE);
156-
#else
169+
# else
157170
ssize_t ret;
158-
# ifdef cfr
171+
# ifdef cfr
159172
if (!(ret= cfr(src, dst, size)))
160173
return int(ret);
161-
# ifdef __linux__
174+
# ifdef __linux__
162175
if (errno == EOPNOTSUPP)
163-
# endif
164-
# endif
165-
# ifdef __linux__ // starting with Linux 2.6.33, we can rely on sendfile(2)
176+
# endif // __linux__
177+
# endif // cfr
178+
# ifdef __linux__ // starting with Linux 2.6.33, we can rely on sendfile(2)
166179
ret= copy<send_step>(src, dst, size);
167-
# else
180+
# else
168181
if ((ret= mmap_copy(src, dst, size)) == 1)
169182
ret= pread_write(src, dst, size);
170-
# endif
183+
# endif // __linux__
171184
DBUG_ASSERT(ret <= 0);
172185
return int(ret);
173-
#endif
186+
# endif // __APPLE__
187+
}
188+
#endif // _WIN32
174189
}
175-
#endif
176-
}

sql/handler.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,7 +1906,7 @@ struct handlerton : public transaction_participant
19061906
@return error code
19071907
@retval 0 on success
19081908
*/
1909-
int (*backup_start)(THD *thd, backup::target_dir_t target);
1909+
int (*backup_start)(THD *thd, Backup_target target);
19101910
/**
19111911
Process a file that was collected in backup_start().
19121912
@param thd current session
@@ -1929,7 +1929,7 @@ struct handlerton : public transaction_participant
19291929
@return error code
19301930
@retval 0 on success
19311931
*/
1932-
int (*backup_finalize)(THD *thd, backup::target_dir_t target);
1932+
int (*backup_finalize)(THD *thd, Backup_target target);
19331933

19341934
/**********************************************************************
19351935
WSREP specific

sql/sql_backup.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static my_bool backup_start(THD *thd, plugin_ref plugin, void *dst) noexcept
2727
{
2828
handlerton *hton= plugin_hton(plugin);
2929
if (hton->backup_start)
30-
return hton->backup_start(thd, to_target_dir(dst));
30+
return hton->backup_start(thd, to_target(dst));
3131
return false;
3232
}
3333

@@ -54,7 +54,7 @@ static my_bool backup_finalize(THD *thd, plugin_ref plugin, void *dst) noexcept
5454
{
5555
handlerton *hton= plugin_hton(plugin);
5656
if (hton->backup_finalize)
57-
return hton->backup_finalize(thd, to_target_dir(dst));
57+
return hton->backup_finalize(thd, to_target(dst));
5858
return 0;
5959
}
6060

storage/innobase/handler/backup_innodb.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InnoDB_backup
5151
std::vector<lsn_t> logs;
5252

5353
/** target directory name or handle */
54-
target_dir_t target;
54+
Target target;
5555

5656
/** the checkpoint from which the backup starts */
5757
lsn_t checkpoint;
@@ -65,7 +65,7 @@ class InnoDB_backup
6565
@return error code
6666
@retval 0 on success
6767
*/
68-
int init(THD *thd, target_dir_t target) noexcept
68+
int init(THD *thd, Target target) noexcept
6969
{
7070
trx_t *trx= check_trx_exists(thd);
7171
if (trx->id || trx->state != TRX_STATE_NOT_STARTED)
@@ -269,7 +269,7 @@ class InnoDB_backup
269269
@return error code
270270
@retval 0 on success
271271
*/
272-
int fini(THD *thd, target_dir_t target) noexcept
272+
int fini(THD *thd, Target target) noexcept
273273
{
274274
int fail= 0;
275275
log_sys.latch.wr_lock();
@@ -650,7 +650,7 @@ void log_t::backup_stop(uint64_t old_size, THD *thd) noexcept
650650
resize_finish(thd);
651651
}
652652

653-
int innodb_backup_start(THD *thd, target_dir_t target) noexcept
653+
int innodb_backup_start(THD *thd, Backup_target target) noexcept
654654
{
655655
return innodb_backup.init(thd, target);
656656
}
@@ -665,7 +665,7 @@ int innodb_backup_end(THD *thd, bool abort) noexcept
665665
return innodb_backup.end(thd, abort);
666666
}
667667

668-
int innodb_backup_finalize(THD *thd, target_dir_t target) noexcept
668+
int innodb_backup_finalize(THD *thd, Backup_target target) noexcept
669669
{
670670
return innodb_backup.fini(thd, target);
671671
}

storage/innobase/handler/backup_innodb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
@return error code
2323
@retval 0 on success
2424
*/
25-
int innodb_backup_start(THD *thd, backup::target_dir_t target) noexcept;
25+
int innodb_backup_start(THD *thd, Backup_target target) noexcept;
2626

2727
/**
2828
Process a file that was collected in backup_start().
@@ -48,7 +48,7 @@ int innodb_backup_end(THD *thd, bool abort) noexcept;
4848
@return error code
4949
@retval 0 on success
5050
*/
51-
int innodb_backup_finalize(THD *thd, backup::target_dir_t target) noexcept;
51+
int innodb_backup_finalize(THD *thd, Backup_target target) noexcept;
5252

5353
/**
5454
Complete the first checkpoint in a new archive log file.

0 commit comments

Comments
 (0)