Skip to content
Johan Wikman edited this page Aug 29, 2018 · 17 revisions

From 2.2 onwards MaxScale will be built as C++. That does not mean that MaxScale will be rewritten in C++ but that C++ can be used were appropriate.

General Rules

MaxScale 2.3 explicitly compiled with -std=c++11

On CentOS 6, MaxScale 2.3 is compiled using the devtoolset-4-gcc-c++ package. This enables the use of GCC 5.3 and full C++11 compatibility. This makes GCC 4.8 the oldest supported compiler (Ubuntu Trusty and Debian Jessie).

MaxScale 2.2 explicitly compiled with -std=c++0x

That is what is available on all platforms officially supported by MaxScale.

The oldest OS that MaxScale is built and packaged for is CentOS 6 (whose GCC is version 4.4). This means that some C++11 features are supported but not all. Please check this list of implemented features to see what C++11 features are available in GCC 4.4 before taking them into use.

MaxScale code must not throw exceptions.

The corollary of that is that the reserving of some resources can fail, then the reserving cannot be done in the constructor. In practice that means that there must be a separate create-function that reserves the resources and once reserved, creates the object or returns NULL, or the equivalent, if the creation fails.

class Heavy
{
public:
    static Heavy* create(...)
    {
       Heavy* pThis = NULL;
       auto_ptr<Resource> sResource(...);
       if (sResource.get())
       {
           pThis = new (std::nothrow) Heavy(sResource);
       }

       return pThis;
    }

private:
    Heavy(auto_ptr<Resource> sResource)
        : m_sResource(sResource)
    {
    }

private:
    auto_ptr<Resource> m_sResource;
};

Note that although MaxScale code itself must not throw exceptions, the runtime-library may do so (e.g. new if the allocation fails).

MaxScale C++ code should be exception safe

Even though MaxScale code itself must not throw exceptions, new C++ code should be exception safe. That is, the code should be written so that even if an exception occurs, all resources are freed appropriately and MaxScale can continue to run. Guard objects should be used for ensuring the release of resources in preference of try-catch blocks.

In practice, since MaxScale consists of a large C-code base, it is a long term goal to make all of MaxScale exception safe.

Exceptions must not be allowed to pass module boundaries.

Under no circumstances must exceptions be allowed to cross module boundaries. That is handled automatically if the templates maxscale::Filter and maxscale::Router are used.

Guidelines