Add MicroSeconds-to-Native-Timer-Units convertor function

Summary: This diff adds a function to convert microseconds (in double) to native timer units (in ulonglong)

Test Plan: jenkins

Reviewers: steaphan

Reviewed By: steaphan
Added configurable histogram step sizes

Summary:
This diff adds more server start up variables to the list of SHOW VARIABLES output.
These can configure the step sizes of different histograms on server start up.
Innodb_histogram_step_size_async_read
Innodb_histogram_step_size_async_write
Innodb_histogram_step_size_sync_read
Innodb_histogram_step_size_sync_write
Innodb_histogram_step_size_log_write
Innodb_histogram_step_size_double_write

Their default start value is set to 16 microseconds.

Test Plan:
sys_vars
show_variables_histogram
jenkins

Reviewers: rongrong, steaphan

Reviewed By: rongrong
Adding Histograms to track I/O Latencies

Summary:
This diff adds 6 histograms to track I/O latencies: async reads|writes, sync reads|writes, log writes, double buffer writes.
The histograms added are:
h_async_write
h_async_read
h_sync_read
h_sync_write
h_log_write
h_double_write

The latency for synchronous I/O operations is simply the time taken by the calling thread to service the I/O request.
In case of asynchronous I/O, there are 2 kinds of latencies:
1. Latency during native I/O:
Here, starting from the time a slot is reserved in the request array (reservation_time) till the time the helper thread waits to collect the completed I/O request from the array, is tracked by the histogram.

2. Latency during simulated I/O
Here, starting from the time a slot is reserved in the request array (reservation_time) till the time synchronous I/O is completed, is tracked by the histogram (waiting time in the request array + time taken to do sync I/O)

Test Plan: jenkins

Reviewers: rongrong, steaphan

Reviewed By: steaphan
Converting Histogram class to a C Structure

Summary:
This diff converts the Histogram class into a structure, in order to be compatible with innodb coding conventions.
The related changes are:
Converting constructor to xxx_init() function
Converting all previous member functions of histogram class along with the destructor into separate functions taking the histogram as input
Changing the function calls in os/os0file.cc

This also changes the variable/functione names related to histogram to make them more descriptive.

Test Plan: jenkins

Reviewers: steaphan, rongrong

Reviewed By: steaphan
Fix for MySQL BUG#69471

Summary:
Fix for MySQL BUG#69471: UNION of derived tables returns wrong results
with false clauses.

There already existed some logic so that if we are optimizing
SELECT2 in SELECT1 ... FROM (SELECT2) we never set best_rowcount
to zero or one unless we are sure that this count is exact.
Indeed a count of zero or one has the consequence that SELECT1
treats the derived table as constant, a decision which cannot be rolled
back, and which leads to catastrophic consequences if, when we later
materialize, the derived table turns out to not have the
anticipated row count. The logic in question forgot to apply
itself to this case: SELECT1 ... FROM (SELECT2 UNION SELECT3 etc.)

We got this patch from ORACLE.

Test Plan:
This diff adds a test file to make sure that the Oracle BUG #69471 was
really fixed.

Also tested:

CREATE TABLE table1 ( a INT, b INT);
CREATE TABLE table2 ( a INT, b INT);
INSERT INTO table1 VALUES (1, 4);
INSERT INTO table1 VALUES (2, 4);
INSERT INTO table2 VALUES (1, 5);
INSERT INTO table2 VALUES (2, 5);

SELECT *
FROM  (
	(SELECT *
           FROM table1
          WHERE 1=0)
UNION
       	 (SELECT *
     	    FROM (SELECT * from table2) t2
           WHERE t2.b = 5)
        ) a3
;

on new 5.6 RPM.

Returns the result

1	5
2	5

correctly now.

Reviewers: jtolmer, steaphan

Reviewed By: steaphan
Port oracle's fix for slave deadlock

Summary:
Ports Oracle's fix for slave deadlock due to master_info_repository=TABLE
and add tests

Link to the public bug: bugs.mysql.com/bug.php?id=69493

Problem:
If a client thread on a slave does FLUSH TABLES WITH READ
LOCK; then master does some updates, SHOW SLAVE STATUS in
the same client will be blocked. If the blocked slave server
is killed and restarted when GTID's are enabled, one GTID
gets missed leaving the slave in an out of sync state.

Using 'relay-log-recovery=1' should do a crash safe slave
recovery but it is not happening.

Analysis:

RPL info tables "slave_master_info" and "slave_relay_log_info"
are used to store slave's thread's positions.  When a FTWRL
is issued on slave this command blocks all operations on
tables. Hence when some update operations are done on master
the slave thread will be able to open the tables but while
closing, an internal commit operation will be blocked. These
blocked info tables make the "SHOW SLAVE STATUS" to hang.

When "relay-log-recovery=1" during crash recovery all the
partial written events will be discarded the master info
table is initialised with the information read from relay
log info table. The "Retrieved GTID" set should be cleared
so that partial read events are discarded and they are
fetched once again. Since this is not happening
"The Retried GTID" is considered to be executed and the
actual transaction is skipped.

Fix:

Info tables should be made independent of global read lock.
At the time of opening the RPL info tables the following
"MYSQL_OPEN_IGNORE_GLOBAL_READ_LOCK" flag is set to make
the info tables not to block when the FTWRL is in progress.
Hence a similar flag is introduced in "ha_commit_trans"
code which will allow commit to complete even if a global
read lock is active. This flag can be used to allow changes
to internal tables (e.g. slave status tables).

To fix the missing GTID issue using "relay-log-recovery"
option, during recovery process retrieved GTID set is cleared.
@ mysql-test/suite/rpl/t/rpl_check_gtid-slave.opt
The script has several subparts which does not require the
"relay-log-recovery" option to be set. Only part 8 and 9
require this option. Since the "relay-log-recovery=1" is
present as part of "rpl_restart_parameters" the opt file is
not necessary and has been removed.
@ mysql-test/suite/rpl/t/rpl_check_gtid.test
Post Bug#16387720 fix at the time of relaylog recovery
the previous GTIDs set will be empty.

@ sql/handler.cc
Added a new "ignore_global_read_lock" flag to make the
commits not to block when global read lock is in effect.
@ sql/handler.h
Overloaded "ha_commit_trans" method by adding a new flag
"ignore_global_read_lock".
@ sql/rpl_info_table_access.cc
Set the "ignore_global_read_lock" flag to true to make the
rpl info tables independent of global read lock.
@ sql/rpl_slave.cc
During recovery reset the "retrieved GTID set"

Test Plan:
mtr

Reviewers: jtolmer

Reviewed By: jtolmer
Add mysqldump option to print ordering key

Summary:
The --print-ordering-key option to mysqldump causes mysqldump to get the
key which is used to order the rows for each table, and print it to the
dump file.

This will help to efficiently run a diff on two mysqldumps of the same
database at different points of time.

Test Plan:
Ran mysqldump with this option. Sample output snippet:

CREATE TABLE `xid_map` (
  `fbid` bigint(20) unsigned NOT NULL DEFAULT '0',
  `fbtype` int(10) unsigned NOT NULL DEFAULT '0',
  `xid` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`fbid`),
  UNIQUE KEY `fbtype_xid` (`fbtype`,`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;
/* ORDERING KEY : fbtype_xid */;

LOCK TABLES `xid_map` WRITE;
/*!40000 ALTER TABLE `xid_map` DISABLE KEYS */;
INSERT INTO `xid_map` VALUES  .....

Checked that the rows are actually sorted with respect to printed key.

Reviewers: steaphan

Reviewed By: steaphan
Port v5.1 New Compression: "refactor page_zip_decompress_clust()" to 5.6

Summary:
This diff refactors page_zip_decompress_clust() by

* rewriting page_zip_decompress_clust() so that it calls
page_zip_decompress_clust_rec() in a loop to decompress records.

* encapsulating restoring of the uncompressed fields in a function.

Test Plan: Jenkins (arc unit)

Reviewers: rongrong, nizamordulu

Reviewed By: nizamordulu
Port v5.1 "Rewrite page_zip_(de)compress_node_ptrs()" to 5.6

Summary:
Port v5.1 "Rewrite page_zip_(de)compress_node_ptrs() to use page_zip_(re)store_uncompressed_fields" to 5.6

As the title says. This is just a refactorization of code to
separate the storing of uncompressed columns from the compression itself
for node pointer pages.

Test Plan: Jenkins (arc unit)

Reviewers: rongrong, nizamordulu

Reviewed By: nizamordulu
Port v5.1 New Compression "Move the shared code out of page_zip_decompress_* functions"

Summary:
Decompressing a page consists of the following steps:
1 - Restore the records from the uncompressed page image.
2 - Clear the unused heap space in the uncompressed page.
3 - Apply modification log.
4 - Verify that the trailer part of the page did not
overlap with the data part of the page.
5 - Restore the uncompressed fields (trx_id, roll_ptr for
primary leaf pages, REC_NODE_PTR length fields for node pointer
pages, nothing for secondary leaf pages.)
6 - Set extra bytes for each record.

Except for the first step, all of the steps are almost identical
for all page types. In addition to this, when we serialize the
records on the page before compression, we will do this in the
first step and not change the other steps. This revision takes the
steps 2 - 6 outside of page_zip_decompress_* functions.

Test Plan: Jenkins (arc unit)

Reviewers: rongrong, nizamordulu

Reviewed By: nizamordulu
Change default value of rpl_receive_buffer_size to 2MB

Summary:
Change default value of rpl_receive_buffer_size to 2MB.

Test Plan: sys_var test case

Reviewers: steaphan, yoshinori

Reviewed By: steaphan
New conf option for SO_SNDBUF in dump thread.

Summary:
A new configuration option rpl_send_buffer_size is added
to control the TCP send buffer size of the socket used in dump thread.

Test Plan: All mts tests passed. Yoshi verified the patch.

Reviewers: yoshinori, steaphan

Reviewed By: steaphan
Remove hard-coded aio disable from mtr.

Summary:
An obsolete hard-coded limit in mtr prevented testing using aio with --mem.

Confirmed this is completely obsolete in all our kernels, then removed it.

Note: This bug was fixed in the linux-2.6.27 release:
	http://kernelnewbies.org/Linux_2_6_27

Test Plan: Jenkins: 'arc unit' - all tests still pass.

Reviewers: jtolmer

Reviewed By: jtolmer