summaryrefslogtreecommitdiffstats
path: root/wsrep-lib/dbsim/db_params.cpp
blob: 40433f6c2a024ab194e8462fc2b82d0b977ca666 (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
/*
 * 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 "db_params.hpp"

#include <boost/program_options.hpp>
#include <iostream>
#include <stdexcept>

namespace
{
    void validate_params(const db::params& params)
    {
        std::ostringstream os;
        if (params.n_servers != params.topology.size())
        {
            if (params.topology.size() > 0)
            {
                os << "Error: --topology=" << params.topology << " does not "
                   << "match the number of server --servers="
                   << params.n_servers << "\n";
            }
        }
        if (os.str().size())
        {
            throw std::invalid_argument(os.str());
        }
    }
}

db::params db::parse_args(int argc, char** argv)
{
    namespace po = boost::program_options;
    db::params params;
    po::options_description desc("Allowed options");
    desc.add_options()
        ("help", "produce help message")
        ("wsrep-provider",
         po::value<std::string>(&params.wsrep_provider)->required(),
         "wsrep provider to load")
        ("wsrep-provider-options",
         po::value<std::string>(&params.wsrep_provider_options),
         "wsrep provider options")
        ("status-file",
         po::value<std::string>(&params.status_file),
         "status output file")
        ("servers", po::value<size_t>(&params.n_servers)->required(),
         "number of servers to start")
        ("topology", po::value<std::string>(&params.topology),
         "replication topology (e.g. mm for multi master, ms for master/slave")
        ("clients", po::value<size_t>(&params.n_clients)->required(),
         "number of clients to start per master")
        ("transactions", po::value<size_t>(&params.n_transactions),
         "number of transactions run by a client")
        ("rows", po::value<size_t>(&params.n_rows),
         "number of rows per table")
        ("max-data-size", po::value<size_t>(&params.max_data_size),
         "maximum size of data payload (default 8)")
        ("random-data-size", po::value<bool>(&params.random_data_size),
         "randomized payload data size (default 0)")
        ("alg-freq", po::value<size_t>(&params.alg_freq),
         "ALG frequency")
        ("sync-wait", po::value<bool>(&params.sync_wait),
         "Turn on sync wait for each transaction")
        ("debug-log-level", po::value<int>(&params.debug_log_level),
         "debug logging level: 0 - none, 1 - verbose")
        ("fast-exit", po::value<int>(&params.fast_exit),
         "exit from simulation without graceful shutdown")
        ("ti",
         po::value<int>(&params.thread_instrumentation),
         "use instrumentation for threads/mutexes/condition variables"
         "(0 default disabled, 1 total counts, 2 per object)")
        ("ti-cond-checks",
         po::value<bool>(&params.cond_checks),
         "Enable checks for correct condition variable use. "
         " Effective only if thread-instrumentation is enabled")
        ("tls-service",
         po::value<int>(&params.tls_service),
         "Configure TLS service stubs.\n0 default disabled\n1 enabled\n"
         "2 enabled with short read/write and renegotiation simulation\n"
         "3 enabled with error simulation.")
        ;
    try
    {
        po::variables_map vm;
        po::store(po::parse_command_line(argc, argv, desc), vm);
        if (vm.count("help"))
        {
            std::cerr << desc << "\n";
            exit(0);
        }
        po::notify(vm);
        validate_params(params);
    }
    catch (const po::error& e)
    {
        std::cerr << "Error parsing arguments: " << e.what() << "\n";
        std::cerr << desc << "\n";
        exit(1);
    }
    catch (...)
    {
        std::cerr << "Error parsing arguments\n";
        std::cerr << desc << "\n";
        exit(1);
    }
    return params;
}