Revert "Adapted some of Intel's patches to zlib"

Summary:
We have been dealing with failed assertions in crash recovery of
compressed tables lately. git bisect revealed the referenced
commit as the culprit. Applying a revert commit has solved the
problem.
Instead of doing a detailed fault analysis, I am just submitting
a revert commit to get this fixed quickly. If there is reasonable
gain from these optimisations, we can go back to debugging this.

Test Plan:
I have done manual testing to check that the crashes in crash
recovery stop. MTRs will do the rest.

Reviewers: rongrong, steaphan

Reviewed By: steaphan
Fix uninitialized variable

Summary:
Because of the "err:" label, it was theoretically possible to jump and
skip all assignments of this variable before it is read.

Test Plan: Compiled with cleaned up build script, now it builds.

Reviewers: santoshb, jtolmer

Reviewed By: jtolmer
[xtrabackup] Fix various issues with the build

Summary:
Pull in CXXFLAGS, not CFLAGS, for CXXFLAGS.  In case the base flags are
different for C and C++, these should obviously be kept separate.

Pass through some missing vars into xtrabackup's cmake run, and
properly initialize them.

Use the same build tools, compiler, etc. for libarchive builds too.

Disable search for unused components in libarchive.

Fix an upstream typo (CFXXLAGS -> CXXFLAGS).

Test Plan: Jenkins

Reviewers: chip, rongrong, tianx, pengt

Reviewed By: chip, rongrong, tianx, pengt
[xtrabackup] Add command line option to disable background threads

Summary:
The innodb code is prepared to be run with background tasks switched
off. Setting srv_force_recovery to a value of 2
(SRV_FORCE_NO_BACKGROUND) or higher disables background threads,
such as the purge threads. Unfortunately, that imples
SRV_FORCE_IGNORE_CORRUPT, which disables page consistency checks.
So instead of using srv_force_recovery, this diff adds a few
ifdef XTRABACKUPs to achieve the effect of SRV_FORCE_NO_BACKGROUND
without SRV_FORCE_IGNORE_CORRUPT.

Test Plan:
Manual testing.
Enabling this did avoid a rare failure in certain special workloads.

Reviewers: steaphan

Reviewed By: steaphan
Reduce the race condition in async defragment

Summary:
We check whether an item is removed from defrag list before rate
limiting in defragment thread. This leaves a large window for other
thread to decide to kill the query or remove the table which will
crash the following pcur open. Reorder the code to make that less likely
to happen.

Test Plan: hopefully the crash in innodb.innodb_alter_table_defragment will stop.

Reviewers: tianx, over, steaphan

Reviewed By: steaphan
Make sure defragmentation don't block super read only

Summary:
defragmentation is not changing the table in any logical sense so it should not
hold the mdl lock that would block super read only. Set the flag correctly.

Test Plan: added a new test to make sure super read only is not blocked. test would deadlock withouth this change.

Reviewers: steaphan, over

Reviewed By: over
fix a bug in document column that sometimes crashes server

Summary:
This patch fixes a double-free bug when inserting larger document into document
column that sometimes will crash server.

Test Plan: Added a regression test case. Run jenkins.

Reviewers: pengt

Reviewed By: pengt
json_extract always returns valid JSON value format

Summary:
This patch makes the return values of json_extract() to be all valid
json value format. Specifically the following 4 scalar value are
returned differently from before:
* String values are now returned with double-quotes
* True value is returned as "true" (no quotes) instead of 1
* False value is returned as "false" (no quotes) instead of 0
* Null value is returned as "null" (no quotes) instead of NULL value.

Test Plan: json test suite

Reviewers: pengt

Reviewed By: pengt
fix a json_extract partial match problem (merging from fbson)

Summary:
This patch fixes a problem in fbson::ObjectVal::find(), such that in some cases
when we search for a key path, only the prefix of the key path will be matched.

Added regression tests in json_func_common.inc and updated test file.

Test Plan: jenkins

Reviewers: pengt

Reviewed By: pengt
Add json_extract_value() builtin which returns raw value

Summary:
We added another builtin function json_extract_value() to get raw value from a
key path. The difference of this function from json_extract() is as follows:

- String value is returned without double quotes
- True value is returned as 1
- False value is return as 0
- Null value is returned as NULL

Note: similar to json_extract, json_extract_value's return type is also text.

Added new test cases for json_extract_value().

Test Plan:
- json test suite
- jenkins

Reviewers: pengt

Reviewed By: pengt
Remove macros that are no longer needed in item_jsonfunc.h

Summary:
The macros were added as part of rapidjson integration. Since we are using
FBSON now, these macros are no longer needed.

Test Plan: jenkins

Reviewers: steaphan

Reviewed By: steaphan
Fail the insertion for invalid JSON if the document field cannot be NULL

Summary: Currently we simply insert NULL and return warnings if the JSON is not valid. This is fine if the document field can be NULL. If the field cannot be NULL, we should fail the whole insertion and return errors.

Test Plan: Jenkins

Reviewers: tianx

Reviewed By: tianx
Support SSL_CONNECTIONS_TOTAL in user_statistics

Summary:
information_schema.user_statistics does not contain SSL connection count
Based on percona patch, I add CONNECTIONS_SSL_TOTAL to our code base

Reference:
https://code.launchpad.net/~vlad-lesin/percona-server/issue-21170-ssl_connections_counting/+merge/105612

Test Plan: mysqltest.sh ssl_connections_count

Reviewers: rongrong

Reviewed By: rongrong
Allow blocking of create/alter table without a primary key

Summary:
We added a cnf flag to force mysql to validate every created / altered
table has a primary key.

This rule applies only for tables outside mysql	and mtr schema.

The general rule is:
* If a table is created, make sure it has a primary key.
* If a table is altered, validate that we did not drop a primary key
  without adding another.

Test Plan:
mysqltest.sh mysql-test/t/create_no_primary_key_table.test
* This creates tables, alters them, and tests out the different cases.

Reviewers: tianx, steaphan

Reviewed By: tianx, steaphan
Some fixes for warnings found with clang and on MacOS

Summary:
One of these actually looks like an upstream bug.

This is just a sub-set of the changes proposed in:
* https://github.com/facebook/mysql-5.6/pull/7

With just a single, simple, change in syntax.

Test Plan: Jenkins

Reviewers: pengt, tianx

Reviewed By: tianx
Fix super_read_only for DROP TRIGGER

Summary:
Fix issue #10 (super read only does not prevent DROP TRIGGER)

- add super read only handling to mysql_create_and_drop_trigger;
- tweak error message in trans_begin to note whether regular or super
  read only is effective;
- add MTR tests for the above changes and for multi-table update which
  was implemented but not covered in MTR.

Test Plan:
Jenkins
mysqltest.sh sys_vars.super_read_only_basic
mysqltest.sh --release sys_vars.super_read_only_basic
mysqltest.sh --asan sys_vars.super_read_only_basic
mysqltest.sh --valgrind sys_vars.super_read_only_basic

Reviewers: chip, tianx

Reviewed By: tianx