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

« back to all changes in this revision

Viewing changes to src/mongo/s/type_shard.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:
 
1
/**
 
2
 *    Copyright (C) 2012 10gen Inc.
 
3
 *
 
4
 *    This program is free software: you can redistribute it and/or  modify
 
5
 *    it under the terms of the GNU Affero General Public License, version 3,
 
6
 *    as published by the Free Software Foundation.
 
7
 *
 
8
 *    This program is distributed in the hope that it will be useful,
 
9
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *    GNU Affero General Public License for more details.
 
12
 *
 
13
 *    You should have received a copy of the GNU Affero General Public License
 
14
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
#include "mongo/s/type_shard.h"
 
17
 
 
18
#include "mongo/s/field_parser.h"
 
19
#include "mongo/util/mongoutils/str.h"
 
20
 
 
21
namespace mongo {
 
22
 
 
23
    using mongoutils::str::stream;
 
24
 
 
25
    const std::string ShardType::ConfigNS = "config.shards";
 
26
 
 
27
    const BSONField<std::string> ShardType::name("_id");
 
28
    const BSONField<std::string> ShardType::host("host");
 
29
    const BSONField<bool> ShardType::draining("draining");
 
30
    const BSONField<long long> ShardType::maxSize("maxSize");
 
31
    const BSONField<BSONArray> ShardType::tags("tags");
 
32
 
 
33
    ShardType::ShardType() {
 
34
        clear();
 
35
    }
 
36
 
 
37
    ShardType::~ShardType() {
 
38
    }
 
39
 
 
40
    bool ShardType::isValid(std::string* errMsg) const {
 
41
        std::string dummy;
 
42
        if (errMsg == NULL) {
 
43
            errMsg = &dummy;
 
44
        }
 
45
 
 
46
        // All the mandatory fields must be present.
 
47
        if (!_isNameSet) {
 
48
            *errMsg = stream() << "missing " << name.name() << " field";
 
49
            return false;
 
50
        }
 
51
        if (!_isHostSet) {
 
52
            *errMsg = stream() << "missing " << host.name() << " field";
 
53
            return false;
 
54
        }
 
55
 
 
56
        return true;
 
57
    }
 
58
 
 
59
    BSONObj ShardType::toBSON() const {
 
60
        BSONObjBuilder builder;
 
61
 
 
62
        if (_isNameSet) builder.append(name(), _name);
 
63
        if (_isHostSet) builder.append(host(), _host);
 
64
        if (_isDrainingSet) builder.append(draining(), _draining);
 
65
        if (_isMaxSizeSet) builder.append(maxSize(), _maxSize);
 
66
        if (_isTagsSet) builder.append(tags(), _tags);
 
67
 
 
68
        return builder.obj();
 
69
    }
 
70
 
 
71
    bool ShardType::parseBSON(const BSONObj& source, string* errMsg) {
 
72
        clear();
 
73
 
 
74
        std::string dummy;
 
75
        if (!errMsg) errMsg = &dummy;
 
76
 
 
77
        FieldParser::FieldState fieldState;
 
78
        fieldState = FieldParser::extract(source, name, &_name, errMsg);
 
79
        if (fieldState == FieldParser::FIELD_INVALID) return false;
 
80
        _isNameSet = fieldState == FieldParser::FIELD_SET;
 
81
 
 
82
        fieldState = FieldParser::extract(source, host, &_host, errMsg);
 
83
        if (fieldState == FieldParser::FIELD_INVALID) return false;
 
84
        _isHostSet = fieldState == FieldParser::FIELD_SET;
 
85
 
 
86
        fieldState = FieldParser::extract(source, draining, &_draining, errMsg);
 
87
        if (fieldState == FieldParser::FIELD_INVALID) return false;
 
88
        _isDrainingSet = fieldState == FieldParser::FIELD_SET;
 
89
 
 
90
        fieldState = FieldParser::extract(source, maxSize, &_maxSize, errMsg);
 
91
        if (fieldState == FieldParser::FIELD_INVALID) return false;
 
92
        _isMaxSizeSet = fieldState == FieldParser::FIELD_SET;
 
93
 
 
94
        fieldState = FieldParser::extract(source, tags, &_tags, errMsg);
 
95
        if (fieldState == FieldParser::FIELD_INVALID) return false;
 
96
        _isTagsSet = fieldState == FieldParser::FIELD_SET;
 
97
 
 
98
        return true;
 
99
    }
 
100
 
 
101
    void ShardType::clear() {
 
102
 
 
103
        _name.clear();
 
104
        _isNameSet = false;
 
105
 
 
106
        _host.clear();
 
107
        _isHostSet = false;
 
108
 
 
109
        _draining = false;
 
110
        _isDrainingSet = false;
 
111
 
 
112
        _maxSize = 0;
 
113
        _isMaxSizeSet = false;
 
114
 
 
115
        _tags = BSONArray();
 
116
        _isTagsSet = false;
 
117
 
 
118
    }
 
119
 
 
120
    void ShardType::cloneTo(ShardType* other) const {
 
121
        other->clear();
 
122
 
 
123
        other->_name = _name;
 
124
        other->_isNameSet = _isNameSet;
 
125
 
 
126
        other->_host = _host;
 
127
        other->_isHostSet = _isHostSet;
 
128
 
 
129
        other->_draining = _draining;
 
130
        other->_isDrainingSet = _isDrainingSet;
 
131
 
 
132
        other->_maxSize = _maxSize;
 
133
        other->_isMaxSizeSet = _isMaxSizeSet;
 
134
 
 
135
        other->_tags = _tags;
 
136
        other->_isTagsSet = _isTagsSet;
 
137
 
 
138
    }
 
139
 
 
140
    std::string ShardType::toString() const {
 
141
        return toBSON().toString();
 
142
    }
 
143
 
 
144
} // namespace mongo