~codership/galera/3.x

« back to all changes in this revision

Viewing changes to galera/src/certification.cpp

  • Committer: Alexey Yurchenko
  • Date: 2014-02-06 19:27:50 UTC
  • mfrom: (153.2.15 2.x)
  • Revision ID: alexey.yurchenko@codership.com-20140206192750-n9to0wtjevl69gok
Tags: release_25.3.3(percona)
References lp:1260193 - all supported parameters are now registered before parsing the initial options string, so unrecognized options can be detected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
 
// Copyright (C) 2010-2013 Codership Oy <info@codership.com>
 
2
// Copyright (C) 2010-2014 Codership Oy <info@codership.com>
3
3
//
4
4
 
5
5
#include "certification.hpp"
17
17
    if (cert_debug_on == false) { }             \
18
18
    else log_info << "cert debug: "
19
19
 
20
 
std::string const
21
 
galera::Certification::Param::log_conflicts =
22
 
                     CERTIFICATION_PARAM_LOG_CONFLICTS_STR;
23
 
 
24
 
std::string const
25
 
galera::Certification::Defaults::log_conflicts =
26
 
                     CERTIFICATION_DEFAULTS_LOG_CONFLICTS_STR;
 
20
#define CERT_PARAM_LOG_CONFLICTS galera::Certification::PARAM_LOG_CONFLICTS
 
21
 
 
22
static std::string const CERT_PARAM_PREFIX("cert.");
 
23
 
 
24
std::string const galera::Certification::PARAM_LOG_CONFLICTS(CERT_PARAM_PREFIX +
 
25
                                                             "log_conflicts");
 
26
 
 
27
static std::string const CERT_PARAM_MAX_LENGTH   (CERT_PARAM_PREFIX +
 
28
                                                  "max_length");
 
29
static std::string const CERT_PARAM_LENGTH_CHECK (CERT_PARAM_PREFIX +
 
30
                                                  "length_check");
 
31
 
 
32
static std::string const CERT_PARAM_LOG_CONFLICTS_DEFAULT("no");
27
33
 
28
34
/*** It is EXTREMELY important that these constants are the same on all nodes.
29
35
 *** Don't change them ever!!! ***/
30
 
long const
31
 
galera::Certification::max_length_default = 16384;
32
 
 
33
 
unsigned long const
34
 
galera::Certification::max_length_check_default = 127;
35
 
 
 
36
static std::string const CERT_PARAM_MAX_LENGTH_DEFAULT("16384");
 
37
static std::string const CERT_PARAM_LENGTH_CHECK_DEFAULT("127");
 
38
 
 
39
void
 
40
galera::Certification::register_params(gu::Config& cnf)
 
41
{
 
42
    cnf.add(CERT_PARAM_LOG_CONFLICTS, CERT_PARAM_LOG_CONFLICTS_DEFAULT);
 
43
    /* The defaults below are deliberately not reflected in conf: people
 
44
     * should not know about these dangerous setting unless they read RTFM. */
 
45
    cnf.add(CERT_PARAM_MAX_LENGTH);
 
46
    cnf.add(CERT_PARAM_LENGTH_CHECK);
 
47
}
 
48
 
 
49
/* a function to get around unset defaults in ctor initialization list */
 
50
static int
 
51
max_length(const gu::Config& conf)
 
52
{
 
53
    if (conf.is_set(CERT_PARAM_MAX_LENGTH))
 
54
        return conf.get<int>(CERT_PARAM_MAX_LENGTH);
 
55
    else
 
56
        return gu::Config::from_config<int>(CERT_PARAM_MAX_LENGTH_DEFAULT);
 
57
}
 
58
 
 
59
/* a function to get around unset defaults in ctor initialization list */
 
60
static int
 
61
length_check(const gu::Config& conf)
 
62
{
 
63
    if (conf.is_set(CERT_PARAM_LENGTH_CHECK))
 
64
        return conf.get<int>(CERT_PARAM_LENGTH_CHECK);
 
65
    else
 
66
        return gu::Config::from_config<int>(CERT_PARAM_LENGTH_CHECK_DEFAULT);
 
67
}
36
68
 
37
69
void
38
70
galera::Certification::purge_for_trx_v1to2(TrxHandle* trx)
782
814
    last_preordered_id_    (0),
783
815
    n_certified_           (0),
784
816
    deps_dist_             (0),
 
817
    key_count_             (0),
785
818
 
786
 
    /* The defaults below are deliberately not reflected in conf: people
787
 
     * should not know about these dangerous setting unless they read RTFM. */
788
 
    max_length_           (conf.get<long>("cert.max_length",
789
 
                                          max_length_default)),
790
 
    max_length_check_     (conf.get<unsigned long>("cert.max_length_check",
791
 
                                                   max_length_check_default)),
792
 
    log_conflicts_        (false),
793
 
    key_count_            (0)
794
 
{
795
 
    try // this is for unit tests where conf may lack some parameters
796
 
    {
797
 
        log_conflicts_ = conf.get<bool>(Param::log_conflicts);
798
 
    }
799
 
    catch (gu::NotFound& e)
800
 
    {
801
 
        conf.set(Param::log_conflicts, Defaults::log_conflicts);
802
 
        log_conflicts_ = conf.get<bool>(Param::log_conflicts);
803
 
    }
804
 
}
 
819
    max_length_            (max_length(conf)),
 
820
    max_length_check_      (length_check(conf)),
 
821
    log_conflicts_         (conf.get<bool>(CERT_PARAM_LOG_CONFLICTS))
 
822
{}
805
823
 
806
824
 
807
825
galera::Certification::~Certification()
1055
1073
    try
1056
1074
    {
1057
1075
        bool const old(log_conflicts_);
1058
 
        log_conflicts_ = gu::from_string<bool>(str);
 
1076
        log_conflicts_ = gu::Config::from_config<bool>(str);
1059
1077
        if (old != log_conflicts_)
1060
1078
        {
1061
1079
            log_info << (log_conflicts_ ? "Enabled" : "Disabled")
1066
1084
    {
1067
1085
        gu_throw_error(EINVAL) << "Bad value '" << str
1068
1086
                               << "' for boolean parameter '"
1069
 
                               << Param::log_conflicts << '\'';
 
1087
                               << CERT_PARAM_LOG_CONFLICTS << '\'';
1070
1088
    }
1071
1089
}
1072
1090