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
=== modified file 'sql/handler.cc'
--- sql/handler.cc 2013-12-23 04:24:10 +0000
+++ sql/handler.cc 2014-01-21 14:15:01 +0000
@@ -4291,11 +4291,20 @@
4291int4291int
4292handler::ha_optimize(THD* thd, HA_CHECK_OPT* check_opt)4292handler::ha_optimize(THD* thd, HA_CHECK_OPT* check_opt)
4293{4293{
4294 int result;
4294 DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||4295 DBUG_ASSERT(table_share->tmp_table != NO_TMP_TABLE ||
4295 m_lock_type == F_WRLCK);4296 m_lock_type == F_WRLCK);
4296 mark_trx_read_write();4297 mark_trx_read_write();
42974298
4298 return optimize(thd, check_opt);4299 result= optimize(thd, check_opt);
4300 /* Forbid returning HA_ADMIN_TRY_ALTER if handler supports online OPTIMIZE as
4301 this combination may result in a deadlock between OPTIMIZE and a concurrent
4302 online ALTER: online OPTIMIZE will downgrade its MDL lock to SW, enabling
4303 ALTER to MDL lock SU, lock the table TL_READ, and block on the X upgrade,
4304 while preventing OPTIMIZE to lock the table TL_WRITE. */
4305 DBUG_ASSERT(result != HA_ADMIN_TRY_ALTER
4306 || !(ha_table_flags() & HA_CAN_WRITE_DURING_OPTIMIZE));
4307 return result;
4299}4308}
43004309
43014310
43024311
=== modified file 'sql/handler.h'
--- sql/handler.h 2013-12-16 12:54:12 +0000
+++ sql/handler.h 2014-01-21 14:15:01 +0000
@@ -248,6 +248,12 @@
248*/248*/
249#define HA_BLOCK_CONST_TABLE (LL(1) << 42)249#define HA_BLOCK_CONST_TABLE (LL(1) << 42)
250250
251/*
252 Storage engine implements online OPTIMIZE and does not return
253 HA_ADMIN_TRY_ALTER for it.
254*/
255#define HA_CAN_WRITE_DURING_OPTIMIZE (LL(1) << 63)
256
251/* bits in index_flags(index_number) for what you can do with index */257/* bits in index_flags(index_number) for what you can do with index */
252#define HA_READ_NEXT 1 /* TODO really use this flag */258#define HA_READ_NEXT 1 /* TODO really use this flag */
253#define HA_READ_PREV 2 /* supports ::index_prev */259#define HA_READ_PREV 2 /* supports ::index_prev */
254260
=== modified file 'sql/mdl.cc'
--- sql/mdl.cc 2013-12-05 17:23:10 +0000
+++ sql/mdl.cc 2014-01-21 14:15:01 +0000
@@ -2812,7 +2812,8 @@
28122812
28132813
2814/**2814/**
2815 Downgrade an EXCLUSIVE or SHARED_NO_WRITE lock to shared metadata lock.2815 Downgrade an EXCLUSIVE, SHARED_NO_WRITE, or SHARED_NO_READ_WRITE lock to
2816 shared metadata lock.
28162817
2817 @param type Type of lock to which exclusive lock should be downgraded.2818 @param type Type of lock to which exclusive lock should be downgraded.
2818*/2819*/
@@ -2833,7 +2834,8 @@
28332834
2834 /* Only allow downgrade from EXCLUSIVE and SHARED_NO_WRITE. */2835 /* Only allow downgrade from EXCLUSIVE and SHARED_NO_WRITE. */
2835 DBUG_ASSERT(m_type == MDL_EXCLUSIVE ||2836 DBUG_ASSERT(m_type == MDL_EXCLUSIVE ||
2836 m_type == MDL_SHARED_NO_WRITE);2837 m_type == MDL_SHARED_NO_WRITE ||
2838 m_type == MDL_SHARED_NO_READ_WRITE);
28372839
2838 mysql_prlock_wrlock(&m_lock->m_rwlock);2840 mysql_prlock_wrlock(&m_lock->m_rwlock);
2839 /*2841 /*
28402842
=== modified file 'sql/sql_admin.cc'
--- sql/sql_admin.cc 2013-12-05 17:23:10 +0000
+++ sql/sql_admin.cc 2014-01-21 14:15:01 +0000
@@ -544,6 +544,14 @@
544 /* purecov: end */544 /* purecov: end */
545 }545 }
546546
547 if (operator_func == &handler::ha_optimize
548 && (table->table->file->ha_table_flags()
549 & HA_CAN_WRITE_DURING_OPTIMIZE)
550 && table->mdl_request.ticket
551 && table->mdl_request.ticket->get_type() == MDL_SHARED_NO_READ_WRITE)
552 {
553 table->mdl_request.ticket->downgrade_lock(MDL_SHARED_WRITE);
554 } else
547 /*555 /*
548 Close all instances of the table to allow MyISAM "repair"556 Close all instances of the table to allow MyISAM "repair"
549 to rename files.557 to rename files.

Subscribers

People subscribed via source and target branches