WL#3836: Method to bring servers off line

Affects: Server-Prototype Only   —   Status: Complete   —   Priority: Medium

In order to be able to upgrade a server, a method need to be developed to bring
a server off line. It should do the following:

- Gracefully force connected clients to disconnect(with appropriate error 
message) except super users (that is, clients with SUPER privilege).
  (Cases like long running queries and abortion of locks are all taken care of)

- Allow super users to connect to manage the system.

- Deny any other user access to the system.
  - Provide a dedicated error message indicating that the server is off-line.

- Allow (all) the replication slave threads to keep applying data to the server.
  (Replication must remain unaffected by this WL)

User Documentation
==================

http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-5.html
http://dev.mysql.com/doc/refman/5.7/en/server-system-
variables.html#sysvar_offline_mode
List of functional requirements:
================================

(1) Server variables
---------------------------------

Func-Req (1.1): The server system variable "offline_mode" is defined. This 
variable is global, and editable only by super users.

Func-Req (1.2): This variable shall be a bool, with default as FALSE.

(2) Functional behavior
-----------------------

Func-Req (2.1): Changes to "offline_mode" system variable from OFF to ON will 
have 
an immediate effect on all sessions. Existing non super-user sessions will be 
disconnected while super users can perform all the functionalities. The 
replication slave thread will continue applying data as usual.

Func-Req (2.2): When "offline_mode" is set to ON, no further non-super user 
clients will be allowed to connect. A dedicated error message 
(ER_SERVER_OFFLINE_MODE) will be thrown. 

Func-Req (2.3): Changing back "offline_mode" from ON to OFF, implies that the 
server will behave as usual.

List of non-functional requirements:
====================================

NF1: All existing features will behave as usual. 
Problem Description:
====================
Currently, there is no mechanism to bring the server to offline mode.
This WL will introduce a mechanism to bring a running server to offline mode for 
upgrades or any other needs.

** Server-side changes **
=========================

Backward/Cross Compatibility
============================
Backward/Cross compatibility is guaranteed by default.

New global system variable
==========================
A new global system variable will be introduced.
Name: offline_mode
Default: OFF
Type: bool

New Error Message
=================
Name: ER_SERVER_OFFLINE_MODE
Message: The server is currently in offline mode.

Implementation w.r.t this WL:
=============================
With this WL we will be able to bring a server into offline mode.
The global variable (offline_mode) will be used as a global policy 
that applies to check if the server is in offline mode or not.
- If this is FALSE then the server is not in offline mode and will behave as 
usual.
- If the super user has set this variable to ON, then the following applies.

  --> All the thread ids of clients connected are retrieved and check if they   
are the super user. If no, then the thread is killed gracefully.Also 
ER_SERVER_OFFLINE_MODE is sent.
  --> All clients who are not the super user will not be allowed to connect.
  --> All the replication threads will continue to run as usual.

- During authentication this variable is checked. If it is set to ON, then all 
non-super user clients will not be allowed sending the new error message.