|
13 | 13 | along with this program; if not, write to the Free Software |
14 | 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ |
15 | 15 |
|
| 16 | +#include "debug_sync.h" |
| 17 | +#include "mdl.h" |
16 | 18 | #include "my_global.h" |
17 | 19 | #include "mysys_err.h" |
18 | 20 | #include "sql_class.h" |
@@ -63,38 +65,58 @@ bool Sql_cmd_backup::execute(THD *thd) |
63 | 65 | error_if_data_home_dir(target.str, "BACKUP SERVER TO")) |
64 | 66 | return true; |
65 | 67 |
|
66 | | - if (my_mkdir(target.str, 0755, MYF(MY_WME))) |
| 68 | + /* |
| 69 | + Block concurrent BACKUP SERVER and BACKUP STAGE |
| 70 | + */ |
| 71 | + MDL_request mdl_request; |
| 72 | + MDL_REQUEST_INIT(&mdl_request, MDL_key::BACKUP, "", "", MDL_BACKUP_START, |
| 73 | + MDL_EXPLICIT); |
| 74 | + if (thd->mdl_context.acquire_lock(&mdl_request, |
| 75 | + thd->variables.lock_wait_timeout)) |
67 | 76 | return true; |
68 | 77 |
|
| 78 | + DEBUG_SYNC(thd, "after_backup_server_lock_acquired"); |
| 79 | + |
| 80 | + bool fail = my_mkdir(target.str, 0755, MYF(MY_WME)); |
| 81 | + |
69 | 82 | #ifndef _WIN32 |
70 | | - int dir= open(target.str, O_DIRECTORY); |
71 | | - if (dir < 0) |
| 83 | + int dir; |
| 84 | + if(!fail) |
72 | 85 | { |
73 | | - my_error(EE_CANT_MKDIR, MYF(ME_BELL), target.str, errno); |
74 | | - return true; |
| 86 | + dir = open(target.str, O_DIRECTORY); |
| 87 | + if (dir < 0) |
| 88 | + { |
| 89 | + my_error(EE_CANT_MKDIR, MYF(ME_BELL), target.str, errno); |
| 90 | + fail= true; |
| 91 | + } |
75 | 92 | } |
76 | 93 | #endif |
77 | 94 |
|
78 | | - bool fail= plugin_foreach_with_mask(thd, backup_start, |
79 | | - MYSQL_STORAGE_ENGINE_PLUGIN, |
80 | | - PLUGIN_IS_DELETED|PLUGIN_IS_READY, |
81 | | - IF_WIN(const_cast<char*>(target.str), |
82 | | - reinterpret_cast<void*>(dir))); |
83 | | - if (!fail) |
84 | | - fail= plugin_foreach_with_mask(thd, backup_step, |
| 95 | + if(!fail) |
| 96 | + { |
| 97 | + fail= plugin_foreach_with_mask(thd, backup_start, |
85 | 98 | MYSQL_STORAGE_ENGINE_PLUGIN, |
86 | | - PLUGIN_IS_DELETED|PLUGIN_IS_READY, nullptr); |
| 99 | + PLUGIN_IS_DELETED|PLUGIN_IS_READY, |
| 100 | + IF_WIN(const_cast<char*>(target.str), |
| 101 | + reinterpret_cast<void*>(dir))); |
| 102 | + |
| 103 | + if (!fail) |
| 104 | + fail= plugin_foreach_with_mask(thd, backup_step, |
| 105 | + MYSQL_STORAGE_ENGINE_PLUGIN, |
| 106 | + PLUGIN_IS_DELETED|PLUGIN_IS_READY, nullptr); |
87 | 107 |
|
88 | | - plugin_foreach_with_mask(thd, backup_end, MYSQL_STORAGE_ENGINE_PLUGIN, |
89 | | - PLUGIN_IS_DELETED|PLUGIN_IS_READY, |
90 | | - reinterpret_cast<void*>(fail)); |
| 108 | + plugin_foreach_with_mask(thd, backup_end, MYSQL_STORAGE_ENGINE_PLUGIN, |
| 109 | + PLUGIN_IS_DELETED|PLUGIN_IS_READY, |
| 110 | + reinterpret_cast<void*>(fail)); |
91 | 111 |
|
92 | | - plugin_foreach_with_mask(thd, backup_finalize, MYSQL_STORAGE_ENGINE_PLUGIN, |
93 | | - PLUGIN_IS_DELETED|PLUGIN_IS_READY, nullptr); |
| 112 | + plugin_foreach_with_mask(thd, backup_finalize, MYSQL_STORAGE_ENGINE_PLUGIN, |
| 113 | + PLUGIN_IS_DELETED|PLUGIN_IS_READY, nullptr); |
94 | 114 | #ifndef _WIN32 |
95 | | - close(dir); |
| 115 | + close(dir); |
96 | 116 | #endif |
97 | 117 |
|
| 118 | + } |
| 119 | + thd->mdl_context.release_lock(mdl_request.ticket); |
98 | 120 | if (!fail) |
99 | 121 | my_ok(thd); |
100 | 122 | return fail; |
|
0 commit comments