Merge lp:~laurynas-biveinis/percona-server/tokudb-non-blocking-optimize into lp:percona-server/5.6

Proposed by Laurynas Biveinis
Status: Rejected
Rejected by: Laurynas Biveinis
Proposed branch: lp:~laurynas-biveinis/percona-server/tokudb-non-blocking-optimize
Merge into: lp:percona-server/5.6
Diff against target: 85 lines (+28/-3)
4 files modified
sql/handler.cc (+10/-1)
sql/handler.h (+6/-0)
sql/mdl.cc (+4/-2)
sql/sql_admin.cc (+8/-0)
To merge this branch: bzr merge lp:~laurynas-biveinis/percona-server/tokudb-non-blocking-optimize
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Disapprove
Registry Administrators Pending
Review via email: mp+202465@code.launchpad.net

This proposal supersedes a proposal from 2014-01-03.

Description of the change

2nd MP:

Explicitly forbid returning HA_ADMIN_TRY_ALTER from optimize if SE supports online optimize, because it might deadlock.
Rebase on the current trunk.

http://jenkins.percona.com/job/percona-server-5.6-param/489/

1st MP:

Add support for storage engines with online OPTIMIZE, implementing
https://blueprints.launchpad.net/percona-server/+spec/allow-writes-during-table-optimization.

The implementation is a combination of
https://github.com/Tokutek/mysql56/commit/1a321b6ae70f76da3dc76c944014baab2b7ce1ae
and
https://github.com/Tokutek/mysql56/commit/a701cea6de67c713d418a319a6a8486da8e07ff2.

It adds a new handler table flag HA_CAN_WRITE_DURING_OPTIMIZE. While
executing OPTIMIZE, after opening the tables, the presence of this
flag is checked and the MDL lock is downgraded from
MDL_SHARED_NO_READ_WRITE to MDL_SHARED_WRITE, and the closing of any
open instances of this table for other connections is skipped.

Adjust MDL_ticker::downgrade_lock() to allow downgrades from
MDL_SHARED_NO_READ_WRITE.

http://jenkins.percona.com/job/percona-server-5.6-param/468/

To post a comment you must log in.
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

MySQL 5.6.17 introduced online OPTIMIZE for InnoDB. Perhaps this can be dropped then, I'll review the 5.6.17 implementation, holding this MP until then.

review: Needs Information
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) wrote :

5.6.16 online OPTIMIZE is a better replacement.

review: Disapprove

Unmerged revisions

535. By Laurynas Biveinis

Add support for storage engines with online OPTIMIZE, implementing
https://blueprints.launchpad.net/percona-server/+spec/allow-writes-during-table-optimization.

The implementation is based on a combination of
https://github.com/Tokutek/mysql56/commit/1a321b6ae70f76da3dc76c944014baab2b7ce1ae
and
https://github.com/Tokutek/mysql56/commit/a701cea6de67c713d418a319a6a8486da8e07ff2

It adds a new handler table flag HA_CAN_WRITE_DURING_OPTIMIZE. While
executing OPTIMIZE, after opening the tables, the presence of this
flag is checked and the MDL lock is downgraded from
MDL_SHARED_NO_READ_WRITE to MDL_SHARED_WRITE, and the closing of any
open instances of this table for other connections is skipped.

Adjust handler::ha_optimize() to assert that HA_ADMIN_TRY_ALTER return
value is incompatible with HA_CAN_WRITE_DURING_OPTIMIZE.

Adjust MDL_ticker::downgrade_lock() to allow downgrades from
MDL_SHARED_NO_READ_WRITE.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'sql/handler.cc'
2--- sql/handler.cc 2013-12-23 04:24:10 +0000
3+++ sql/handler.cc 2014-01-21 14:15:01 +0000
4@@ -4291,11 +4291,20 @@
5 int
6 handler::ha_optimize(THD* thd, HA_CHECK_OPT* check_opt)
7 {
8+ int result;
9 DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
10 m_lock_type == F_WRLCK);
11 mark_trx_read_write();
12
13- return optimize(thd, check_opt);
14+ result= optimize(thd, check_opt);
15+ /* Forbid returning HA_ADMIN_TRY_ALTER if handler supports online OPTIMIZE as
16+ this combination may result in a deadlock between OPTIMIZE and a concurrent
17+ online ALTER: online OPTIMIZE will downgrade its MDL lock to SW, enabling
18+ ALTER to MDL lock SU, lock the table TL_READ, and block on the X upgrade,
19+ while preventing OPTIMIZE to lock the table TL_WRITE. */
20+ DBUG_ASSERT(result != HA_ADMIN_TRY_ALTER
21+ || !(ha_table_flags() & HA_CAN_WRITE_DURING_OPTIMIZE));
22+ return result;
23 }
24
25
26
27=== modified file 'sql/handler.h'
28--- sql/handler.h 2013-12-16 12:54:12 +0000
29+++ sql/handler.h 2014-01-21 14:15:01 +0000
30@@ -248,6 +248,12 @@
31 */
32 #define HA_BLOCK_CONST_TABLE (LL(1) << 42)
33
34+/*
35+ Storage engine implements online OPTIMIZE and does not return
36+ HA_ADMIN_TRY_ALTER for it.
37+*/
38+#define HA_CAN_WRITE_DURING_OPTIMIZE (LL(1) << 63)
39+
40 /* bits in index_flags(index_number) for what you can do with index */
41 #define HA_READ_NEXT 1 /* TODO really use this flag */
42 #define HA_READ_PREV 2 /* supports ::index_prev */
43
44=== modified file 'sql/mdl.cc'
45--- sql/mdl.cc 2013-12-05 17:23:10 +0000
46+++ sql/mdl.cc 2014-01-21 14:15:01 +0000
47@@ -2812,7 +2812,8 @@
48
49
50 /**
51- Downgrade an EXCLUSIVE or SHARED_NO_WRITE lock to shared metadata lock.
52+ Downgrade an EXCLUSIVE, SHARED_NO_WRITE, or SHARED_NO_READ_WRITE lock to
53+ shared metadata lock.
54
55 @param type Type of lock to which exclusive lock should be downgraded.
56 */
57@@ -2833,7 +2834,8 @@
58
59 /* Only allow downgrade from EXCLUSIVE and SHARED_NO_WRITE. */
60 DBUG_ASSERT(m_type == MDL_EXCLUSIVE ||
61- m_type == MDL_SHARED_NO_WRITE);
62+ m_type == MDL_SHARED_NO_WRITE ||
63+ m_type == MDL_SHARED_NO_READ_WRITE);
64
65 mysql_prlock_wrlock(&m_lock->m_rwlock);
66 /*
67
68=== modified file 'sql/sql_admin.cc'
69--- sql/sql_admin.cc 2013-12-05 17:23:10 +0000
70+++ sql/sql_admin.cc 2014-01-21 14:15:01 +0000
71@@ -544,6 +544,14 @@
72 /* purecov: end */
73 }
74
75+ if (operator_func == &handler::ha_optimize
76+ && (table->table->file->ha_table_flags()
77+ & HA_CAN_WRITE_DURING_OPTIMIZE)
78+ && table->mdl_request.ticket
79+ && table->mdl_request.ticket->get_type() == MDL_SHARED_NO_READ_WRITE)
80+ {
81+ table->mdl_request.ticket->downgrade_lock(MDL_SHARED_WRITE);
82+ } else
83 /*
84 Close all instances of the table to allow MyISAM "repair"
85 to rename files.

Subscribers

People subscribed via source and target branches