~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to src/mongo/db/repl/consensus.cpp

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
    class CmdReplSetFresh : public ReplSetCommand {
28
28
    public:
29
29
        CmdReplSetFresh() : ReplSetCommand("replSetFresh") { }
 
30
        virtual void addRequiredPrivileges(const std::string& dbname,
 
31
                                           const BSONObj& cmdObj,
 
32
                                           std::vector<Privilege>* out) {
 
33
            ActionSet actions;
 
34
            actions.addAction(ActionType::replSetFresh);
 
35
            out->push_back(Privilege(AuthorizationManager::SERVER_RESOURCE_NAME, actions));
 
36
        }
30
37
    private:
31
38
 
32
39
        bool shouldVeto(const BSONObj& cmdObj, string& errmsg) {
41
48
            const Member* hopeful = theReplSet->findById(id);
42
49
            const Member *highestPriority = theReplSet->getMostElectable();
43
50
 
44
 
            if( !hopeful ) {
 
51
            if (!hopeful) {
45
52
                errmsg = str::stream() << "replSet couldn't find member with id " << id;
46
53
                return true;
47
54
            }
48
 
            else if( theReplSet->isPrimary() && theReplSet->lastOpTimeWritten >= hopeful->hbinfo().opTime ) {
 
55
 
 
56
            if (theReplSet->isPrimary() &&
 
57
                theReplSet->lastOpTimeWritten >= hopeful->hbinfo().opTime) {
49
58
                // hbinfo is not updated, so we have to check the primary's last optime separately
50
59
                errmsg = str::stream() << "I am already primary, " << hopeful->fullName() <<
51
60
                    " can try again once I've stepped down";
52
61
                return true;
53
62
            }
54
 
            else if( primary && primary->hbinfo().opTime >= hopeful->hbinfo().opTime ) {
 
63
 
 
64
            if (primary && primary->hbinfo().opTime >= hopeful->hbinfo().opTime) {
55
65
                // other members might be aware of more up-to-date nodes
56
 
                errmsg = str::stream() << hopeful->fullName() << " is trying to elect itself but " <<
57
 
                    primary->fullName() << " is already primary and more up-to-date";
58
 
                return true;
59
 
            }
60
 
            else if( highestPriority && highestPriority->config().priority > hopeful->config().priority) {
61
 
                errmsg = str::stream() << hopeful->fullName() << " has lower priority than " << highestPriority->fullName();
62
 
                return true;
63
 
            }
64
 
 
65
 
            if ( !theReplSet->isElectable(id) ||
66
 
                (highestPriority && highestPriority->config().priority > hopeful->config().priority)) {
 
66
                errmsg = str::stream() << hopeful->fullName() <<
 
67
                    " is trying to elect itself but " << primary->fullName() <<
 
68
                    " is already primary and more up-to-date";
 
69
                return true;
 
70
            }
 
71
 
 
72
            if (highestPriority &&
 
73
                highestPriority->config().priority > hopeful->config().priority) {
 
74
                errmsg = str::stream() << hopeful->fullName() << " has lower priority than " <<
 
75
                    highestPriority->fullName();
 
76
                return true;
 
77
            }
 
78
 
 
79
            if (!theReplSet->isElectable(id)) {
 
80
                errmsg = str::stream() << "I don't think " << hopeful->fullName() <<
 
81
                    " is electable";
67
82
                return true;
68
83
            }
69
84
 
95
110
            }
96
111
            result.appendDate("opTime", theReplSet->lastOpTimeWritten.asDate());
97
112
            result.append("fresher", weAreFresher);
98
 
            result.append("veto", shouldVeto(cmdObj, errmsg));
 
113
 
 
114
            bool veto = shouldVeto(cmdObj, errmsg);
 
115
            result.append("veto", veto);
 
116
            if (veto) {
 
117
                result.append("errmsg", errmsg);
 
118
            }
99
119
 
100
120
            return true;
101
121
        }
104
124
    class CmdReplSetElect : public ReplSetCommand {
105
125
    public:
106
126
        CmdReplSetElect() : ReplSetCommand("replSetElect") { }
 
127
        virtual void addRequiredPrivileges(const std::string& dbname,
 
128
                                           const BSONObj& cmdObj,
 
129
                                           std::vector<Privilege>* out) {
 
130
            ActionSet actions;
 
131
            actions.addAction(ActionType::replSetElect);
 
132
            out->push_back(Privilege(AuthorizationManager::SERVER_RESOURCE_NAME, actions));
 
133
        }
107
134
    private:
108
135
        virtual bool run(const string& , BSONObj& cmdObj, int, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
109
136
            if( !check(errmsg, result) )
132
159
 
133
160
    bool Consensus::shouldRelinquish() const {
134
161
        int vUp = rs._self->config().votes;
135
 
        const long long T = rs.config().ho.heartbeatTimeoutMillis * rs.config().ho.heartbeatConnRetries;
136
162
        for( Member *m = rs.head(); m; m=m->next() ) {
137
 
            long long dt = m->hbinfo().timeDown();
138
 
            if( dt < T )
 
163
            if (m->hbinfo().up()) {
139
164
                vUp += m->config().votes;
 
165
            }
140
166
        }
141
167
 
142
168
        // the manager will handle calling stepdown if another node should be