WL#13842: Compile XCom as C++

Affects: Server-8.0   —   Status: Complete

1 HIGH-LEVEL DESCRIPTION
========================================================================
1.1 EXECUTIVE SUMMARY
------------------------------------------------------------------------
Compile XCom as C++. It is compiled as C as of today.
This worklog is expected to accelerate the development of future
worklogs that pertain to XCom due to C++'s higher-level features and
richer standard library.

1.2 RATIONALE
------------------------------------------------------------------------
Work on "MySQL GCS: Decouple XCom transport from XCom core" will
decouple the transport logic from the core Paxos logic in XCom. As part
of the worklog we expect that XCom's core will run on one thread and
XCom's transport will run on another thread, or maybe multiple other
threads.

The design/implementation for Work on "MySQL GCS: Decouple XCom
transport from XCom core" will benefit greatly if XCom migrates from C
to C++, e.g. threads and inter-thread communication. The purpose of this
worklog is to migrate XCom to C++ as a precursor to Work on "MySQL
GCS: Decouple XCom transport from XCom core."

This worklog should migrate XCom to C++ in the mysql and xcom repositories
following the joint XCom developement protocol [1.1] between Group
Replication/GCS and MCM.

To summarise, this is the chain of dependencies:

  Worklog #12844 (common XCom between GR and MCM)
       |
       v
  This worklog (C++)
       |
       v
  Work on decoupling


1.3 USER/DEV STORIES
------------------------------------------------------------------------
As a MySQL Developer, I want to compile XCom as C++ so that I can rely
on C++'s higher-level features and richer standard library to accelerate
development.


1.4 SCOPE
------------------------------------------------------------------------
This worklog shall:
- Modify the XCom source code in order for it to be compilable as C++.

This worklog shall not:
- Upgrade the XCom source code from its current C style to a more
  idiomatic C++ style.

This worklog contributes to the overall vision by laying the ground work
for Work on "MySQL GCS: Decouple XCom transport from XCom core."
This worklog is expected to accelerate the development on future worklogs 
that pertain to XCom due to C++'s higher-level features and richer standard library.
2 REQUIREMENTS
========================================================================
2.1 FUNCTIONAL REQUIREMENTS
------------------------------------------------------------------------
N/A.


2.2 NON-FUNCTIONAL REQUIREMENTS
------------------------------------------------------------------------
NFR1. Compiling XCom as C++ should not impose a runtime performance
      penalty greater than 3%.

NFR2. XCom should compile as C++ as part of the libmysqlgcs.a static
      library.

NFR3. The build system (CMake) should not require any changes to compile
      XCom as C++.
3 INTERFACE SPECIFICATION
========================================================================
3.1 SUMMARY OF THE APPROACH
------------------------------------------------------------------------
Compile XCom as C++ as part of MySQL Group Replication.

3.2 SECURITY CONTEXT
------------------------------------------------------------------------
No foreseeable impact.


3.3 UPGRADE/DOWNGRADE and CROSS-VERSION REPLICATION
------------------------------------------------------------------------
No foreseeable impact.


3.4 USER INTERFACE
------------------------------------------------------------------------
No foreseeable impact.


3.5 OBSERVABILITY
------------------------------------------------------------------------
No foreseeable impact.


3.6 DEPLOYMENT and INSTALLATION
------------------------------------------------------------------------
No foreseeable impact.


3.7 PROTOCOL
------------------------------------------------------------------------
No foreseeable impact.


3.8 FAILURE MODEL SPECIFICATION
------------------------------------------------------------------------
No foreseeable impact.
5 DESIGN SPECIFICATION
========================================================================
5.1 DESIGN DECISIONS
5.1.1 COMPILE AS C++
------------------------------------------------------------------------
There are two options for the build system (CMake) to generate
compilation commands that compile XCom as C++:
a) Rename all the file extensions from .c to .cc, or
b) Instruct CMake to explicitly generate compilation commands that
   compile XCom as C++
With option (a) CMake will automatically understand that XCom should be
compiled as C++.
With option (b) we must change the CMake files to explicitly instruct
CMake to generate compilation commands that compile XCom as C++.

To meet NFR3, we opt for option (a).


5.1.2 C LINKAGE VS. C++ LINKAGE
------------------------------------------------------------------------
We have to decide whether, in general, we continue to compile XCom with
C linkage, i.e. `extern "C"`, or with C++ linkage.

The only apparent reason to compile XCom with C linkage is if we expect
a client to call XCom from a C context. This prevents certain C++
features, e.g. function overloading, unless we go through the work of
defining a C client API to hide all the C++ behind a C interface.

C++ linkage allows for "full" C++, but prevents XCom from being called
from a C context.

We opt for C++ linkage. This means that we remove all the `extern "C"`
linkage declarations.
The only exception is the interaction between XCom and XDR functions,
which are in C. Due to different protocol versions, the XDR functions
may need to call XCom to initialise certain fields.
As a concrete example, the `delivered_msg` field was added to `pax_msg`
in protocol version 2. When XDR deserializes a `pax_msg` from protocol
version 1, it initializes `pax_msg.delivered_msg` by calling XCom's
`get_delivered_msg()` function. `get_delivered_msg()` must have C
linkage to be called from XDR.