remove implicit dependency on my_global.h from mysql.h

Summary:
By using the C_MODE_BEGIN/C_MODE_END macros we include an implicit dependency on my_global.h.  This is different than the Oracle mysql.  This breaks the open source hhvm.  The fbcode version is using the 5.6.12 headers that don't have this impicit dependency.

Despite requiring the mysql.h.pp change this is not an ABI breaking change.  Further evidence of this is the HHVM build with 5.6.12 headers works fine with the mysql 5.6.21.

This diff https://reviews.facebook.net/D17019 has the change.  Interestingly the diff originally did not use C_MODE_BEGIN/C_MODE_END but darnaut pointed out the existance of the macro.

The alternative of including my_global.h everywhere was looked at but it has a few issues.  1) is my_global.h pulls in my_config.h which introduces serveral macros that conflict with HHVM.  2) If our mysql is intended to be open sourced and compete with Oracle, we may want to be compatible.

Test Plan: I tried are unit but 8 hours later it still says: Waiting for build to start...

Reviewers: steaphan

Reviewed By: steaphan
Do not check or try to recover empty doublewrite pages

Summary:
The pages in the doublewrite buffer are fixed.  When the reduced mode is
dynamically enabled, only the first page may be used, so the other pages
are overwritten with blank pages that point to themselves.

Since these pages *may* be used by the (separate) single-page flushing
system, we still have to process them.  The idea was that these pages
would pass the checksums, and so nothing special had to be done.

There is really no point in checking a doublewrite page that points
within the doublewrite buffer itself.  This was just done to keep the
code simple.  So, now, we just ignore these pages entirely.

Test Plan:
Jenkins

mysqltest.sh --clean --release --repeat=16 --parallel=16 --mem \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite \
	innodb.innodb_doublewrite innodb.innodb_doublewrite

Verified using extra logging info that these pages (and *only* these
pages) are being skipped during all this testing.

Reviewers: pengt

Reviewed By: pengt
Merge Oracle's patch for larger InnoDB pages

Summary:
We previously implemented support for larger InnoDB
pages. Oracle has now come out with similar support in the 5.7
labs release. Merge their patch with our code to switch to
their implementation. In the process, we are losing support
for compression when using larger page sizes. But we are gaining
support for 64KB pages.

The Oracle patch built on top of
https://github.com/mysql/mysql-server/commit/b367bc018f.
Adjusting for that was mostly straightforward, replacing
occurrences of page_size.physical() with UNIV_PAGE_SIZE.

Their diff included a change to btr0cur.cc that is not
clear to me why it is included. I will follow up with Oracle.
Please review it carefully because the parameters in 5.6
are different from the labs 5.7 code.

In their patch, they made changes to fsp/fsp0file.cc. That
file is new in 5.7 and was refactored out of fsp/fsp0fsp.cc.
Thus, pay closer attention to the changes I made there too.

Test Plan: Jenkins

Reviewers: over, rongrong

Reviewed By: rongrong
Fix compatibility of undo records with large page size support

Summary:
When we increased InnoDB's maximum page size, we
unintentionally created an incompatibility in the undo record
format for externally stored fields. This diff picks up
Oracle's fix for the issue.

Test Plan: mysqlrpmtest.par --test_region=atn --test_list=replica_new_to_new

Reviewers: over, tianx

Reviewed By: tianx
Teach MySQL how to check SANs that are IP addresses

Summary:
MySQL knew how to handle SANs for hostnames, but not IPv4 and
IPv6 addresses.  This adds that capability.

Test Plan:
tested by hand; connected to hostname, ipv4, and ipv6
addresses on a host with a cert listing the hostname as the subject as
well as ip addresses as alternate names, it worked with certificate
validation enabled.  tried other port with bogus cert, it failed.

Reviewers: agartrell

Reviewed By: agartrell
Fix mysql issue with openssl error codes

Summary:
mysql wasn't using OpenSSL error codes correctly; it was using
the return value of SSL_get_error rather than ERR_get_error, which made
for nonsensical errors.

Before this patch, with a cert signed by an unknown CA, this was the
error:

ERROR 2026 (HY000): SSL connection error: error:00000001:lib(0):func(0):reason(1)

after:

ERROR 2026 (HY000): SSL connection error: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Test Plan: jenkins

Reviewers: steaphan, brianp, santoshb

Reviewed By: brianp, santoshb
Fix ssl timeouts

Summary:
My investigation indicates the O_NONBLOCK flag is not set for mysql socket when a
timeout > 0 is used for SSL. I found the function vio_set_blocking(1) is called at
couple of places even when client is using SSL.

Add aditional checks around vio_set_blocking(1) so the client uses non-blocking sockets for SSL.

Test Plan:
Block master port
sudo iptables -A INPUT -p tcp --destination-port $master_port -j DROP
sudo ip6tables -A INPUT -p tcp --destination-port $master_port -j DROP

Without this patch, slave io_thread blocked on SSL_read(). With this patch slave io_thread
hits connect error promptly with in slave_net_timeout seconds.

Reviewers: jtolmer, chip

Reviewed By: chip
check dump thread killed status while reading binlog events

Summary:
Binlog dump thread might get stuck in the inner loop of mysql_binlog_send
reading events from a slow disk if a slave with very low slave_net_timeout
reconnects often. The situation worsens with increase in binlog zombie
dump threads (cpu contention if semi-sync plugin is enabled).
Adding a thd->killed check kills the zombie dump threads instantly avoiding this issue.

Test Plan:
use GTIDs. Stop slave at high master_log_pos (800MB). drop binlog caches in a loop
(echo 3 > /proc/sys/vm/drop_caches). Verify number of zombie dump threads increasing.

Verified with this patch, zombie dump threads exit immediately.

Reviewers: yoshinori, jtolmer

Reviewed By: jtolmer
fix an assert in mts

Summary:
For queries like "drop database" mts_accessed_db_names is set to
OVER_MAX_DBS_IN_EVENT_MTS and the acutal db is set to empty string "".
sql thread doesn't create gtid info for these kind of queries,
so the slave_gtid_info shouldn't be updated by slave worker thread,
otherwise it hits DBUG_ASSERT(gtid_info);

Test Plan:
mtr test

consistently hit assert/seg-fault with mtr_run rpl.rpl_gtid_mts.test
without this patch.

Reviewers: steaphan, jtolmer

Reviewed By: jtolmer
Send heartbeat events when a GTID group is skipped

Summary:
when using GTID and low slave_net_timeouts on slave, slave
io_thread may get stuck in connecting phase without ever
progressing. This is due to dump thread skipping GTID groups
without sending anything through the network.

Send heartbeat event when a GTID group is skipped so the connection is up
and the slave io_thread doesn't hit net read timeout.

public bug report: http://bugs.mysql.com/bug.php?id=74607

Note: Sends one heartbeat for every 11 skipped events (for perf).

Test Plan:
use GTIDs. Stop slave at high master_log_pos (800MB). drop binlog caches
in a loop (echo 3 > /proc/sys/vm/drop_caches). Verify io_thread is stuck
in connecting phase without ever progressing.

With this patch, io_thread receives binlog events.

mtr rpl.rpl_gtid_mts

Reviewers: jtolmer, yoshinori, steaphan

Reviewed By: jtolmer, steaphan
Enabe FSBON binary output from document related queries

Summary:
This diff adds a new session variable "use_fbson_output_format" to let
MySQL output FBSON binary value without converting it to JSON text. By
default, the variable is turned off (i.e. converted to JSON), so FBSON
output can be read by human.

Example: '{"k1":[1,{"k2":["v1",2,true]},3,false]}'

    select HEX(json_extract(json,'k1',1,'k2',0)) from test_json;

    +-------------------------------------+
    | HEX(json_extract(json,'k1',1,'k2')) |
    +-------------------------------------+
    | 0B0A00000008020000007631030201      |
    +-------------------------------------+

    Equivalent JSON output: ["v1",2,true]

Notes:
- json_extra and json_extract_value will be equivalent since we don't
  convert the binary to JSON text
- Output from JSON extract functions will not contain document header
  (see the example above)
- Selecting document column directly will return the whole FBSON
  document with header
- Enabling binary output will have better performance for document
  columns, as we don't need to convert from binary to JSON text

Test Plan:
suite/json
jenkins

I added a bunch of test cases in fbson_output_format.inc, which was ran
as part of json_func_document.test.

Reviewers: pengt

Reviewed By: pengt
Implemented granular InnoDB status commands

Summary:
Added new commands:
SHOW ENGINE INNODB STATUS BACKGROUND THREAD;
SHOW ENGINE INNODB STATUS SEMAPHORES;
SHOW ENGINE INNODB STATUS FK;
SHOW ENGINE INNODB STATUS FILE;
SHOW ENGINE INNODB STATUS TABLESPACE;
SHOW ENGINE INNODB STATUS INSBUFFER;
SHOW ENGINE INNODB STATUS LOGS;
SHOW ENGINE INNODB STATUS MEMORY;
SHOW ENGINE INNODB STATUS ROW OPERATIONS;

Test Plan: run all tests

Reviewers: tianx, rongrong

Reviewed By: rongrong
Make mysqlbinlog reconnect

Summary:
This patch makes mysqlbinlog reconnect when connection is lost
(i.e. transient network failure), rather than exit immediately,
so that it can work as similar as slave IO thread.
When mysqlbinlog reconnects, it continues to read from file/pos
where the connection was lost. It is much faster than re-reading
from the beginning of the binary log, especially if binlog
size is large.

This patch adds 4 command line variables, heartbeat_period,
max_retries, net_timeout and reconnect_interval.

This patch also fixes off_t does not point proper position
when --start-position is used.

Test Plan:
Jenkins

mysqltest.sh --clean --valgrind --repeat=64 main.mysqlbinlog_streaming

Reviewers: jtolmer, santoshb, steaphan

Reviewed By: santoshb