summaryrefslogtreecommitdiffstats
path: root/wsrep-lib/src/provider.cpp
blob: 9e99f7fddc3c23451e0fa5a0178afb0085cd40d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * Copyright (C) 2018 Codership Oy <info@codership.com>
 *
 * This file is part of wsrep-lib.
 *
 * Wsrep-lib is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * Wsrep-lib is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with wsrep-lib.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "wsrep/provider.hpp"
#include "wsrep/logger.hpp"

#include "wsrep_provider_v26.hpp"

#include <dlfcn.h>
#include <cassert>
#include <memory>

wsrep::provider* wsrep::provider::make_provider(
    wsrep::server_state& server_state,
    const std::string& provider_spec,
    const std::string& provider_options,
    const wsrep::provider::services& services)
{
    try
    {
        return new wsrep::wsrep_provider_v26(
            server_state, provider_options, provider_spec, services);
    }
    catch (const wsrep::runtime_error& e)
    {
        wsrep::log_error() << "Failed to create a new provider '"
                           << provider_spec << "'"
                           << " with options '" << provider_options
                           << "': " << e.what();
    }
    catch (...)
    {
        wsrep::log_error() << "Caught unknown exception when trying to "
                           << "create a new provider '"
                           << provider_spec << "'"
                           << " with options '" << provider_options;
    }
    return 0;
}

std::string
wsrep::provider::to_string(enum wsrep::provider::status const val)
{
    switch(val)
    {
    case success:
        return "Success";
    case error_warning:
        return "Warning";
    case error_transaction_missing:
        return "Transaction not registered with provider";
    case error_certification_failed:
        return "Certification failed";
    case error_bf_abort:
        return "Transaction was BF aborted";
    case error_size_exceeded:
        return "Transaction size exceeded";
    case error_connection_failed:
        return "Not connected to Primary Component";
    case error_provider_failed:
        return "Provider in bad state, needs to be reinitialized.";
    case error_fatal:
        return "Fatal error, must abort.";
    case error_not_implemented:
        return "Function not implemented";
    case error_not_allowed:
        return "Operation not allowed";
    case error_unknown:
        return "Unknown error";
    }

    assert(0);

    std::ostringstream os;
    os << "Invalid error code: " << val;
    return os.str();
}

std::string wsrep::provider::capability::str(int caps)
{
    std::ostringstream os;

#define WSREP_PRINT_CAPABILITY(cap_value, cap_string) \
    if (caps & cap_value) {                           \
        os << cap_string ", ";                        \
        caps &= ~cap_value;                           \
    }

    WSREP_PRINT_CAPABILITY(multi_master,         "MULTI-MASTER");
    WSREP_PRINT_CAPABILITY(certification,        "CERTIFICATION");
    WSREP_PRINT_CAPABILITY(parallel_applying,    "PARALLEL_APPLYING");
    WSREP_PRINT_CAPABILITY(transaction_replay,   "REPLAY");
    WSREP_PRINT_CAPABILITY(isolation,            "ISOLATION");
    WSREP_PRINT_CAPABILITY(pause,                "PAUSE");
    WSREP_PRINT_CAPABILITY(causal_reads,         "CAUSAL_READ");
    WSREP_PRINT_CAPABILITY(causal_transaction,   "CAUSAL_TRX");
    WSREP_PRINT_CAPABILITY(incremental_writeset, "INCREMENTAL_WS");
    WSREP_PRINT_CAPABILITY(session_locks,        "SESSION_LOCK");
    WSREP_PRINT_CAPABILITY(distributed_locks,    "DISTRIBUTED_LOCK");
    WSREP_PRINT_CAPABILITY(consistency_check,    "CONSISTENCY_CHECK");
    WSREP_PRINT_CAPABILITY(unordered,            "UNORDERED");
    WSREP_PRINT_CAPABILITY(annotation,           "ANNOTATION");
    WSREP_PRINT_CAPABILITY(preordered,           "PREORDERED");
    WSREP_PRINT_CAPABILITY(streaming,            "STREAMING");
    WSREP_PRINT_CAPABILITY(snapshot,             "READ_VIEW");
    WSREP_PRINT_CAPABILITY(nbo,                  "NBO");

#undef WSREP_PRINT_CAPABILITY

    if (caps)
    {
        assert(caps == 0); // to catch missed capabilities
        os << "UNKNOWN(" << caps << ")  ";
    }

    std::string ret(os.str());
    if (ret.size() > 2) ret.erase(ret.size() - 2);
    return ret;
}

std::string wsrep::flags_to_string(int flags)
{
    std::ostringstream oss;
    if (flags & provider::flag::start_transaction)
        oss << "start_transaction | ";
    if (flags & provider::flag::commit)
        oss << "commit | ";
    if (flags & provider::flag::rollback)
        oss << "rollback | ";
    if (flags & provider::flag::isolation)
        oss << "isolation | ";
    if (flags & provider::flag::pa_unsafe)
        oss << "pa_unsafe | ";
    if (flags & provider::flag::prepare)
        oss << "prepare | ";
    if (flags & provider::flag::snapshot)
        oss << "read_view | ";
    if (flags & provider::flag::implicit_deps)
        oss << "implicit_deps | ";

    std::string ret(oss.str());
    if (ret.size() > 3) ret.erase(ret.size() - 3);
    return ret;
}

std::ostream& wsrep::operator<<(std::ostream& os, const wsrep::ws_meta& ws_meta)
{
    os <<  "gtid: "      << ws_meta.gtid()
       << " server_id: " << ws_meta.server_id()
       << " client_id: " << ws_meta.client_id()
       << " trx_id: "    << ws_meta.transaction_id()
       << " flags: "     << ws_meta.flags()
       << " (" << wsrep::flags_to_string(ws_meta.flags()) << ")";
    return os;
}