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

« back to all changes in this revision

Viewing changes to src/mongo/s/type_chunk.h

  • 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
 
 
17
#pragma once
 
18
 
 
19
#include <string>
 
20
 
 
21
#include "mongo/base/disallow_copying.h"
 
22
#include "mongo/base/string_data.h"
 
23
#include "mongo/db/jsobj.h"
 
24
#include "mongo/s/chunk_version.h"
 
25
 
 
26
namespace mongo {
 
27
 
 
28
    /**
 
29
     * This class represents the layout and contents of documents contained in the
 
30
     * config.chunks collection. All manipulation of documents coming from that
 
31
     * collection should be done with this class.
 
32
     *
 
33
     * Usage Example:
 
34
     *
 
35
     *     // Contact the config. 'conn' has been obtained before.
 
36
     *     DBClientBase* conn;
 
37
     *     BSONObj query = QUERY(ChunkType::exampleField("exampleFieldName"));
 
38
     *     exampleDoc = conn->findOne(ChunkType::ConfigNS, query);
 
39
     *
 
40
     *     // Process the response.
 
41
     *     ChunkType exampleType;
 
42
     *     string errMsg;
 
43
     *     if (!exampleType.parseBSON(exampleDoc, &errMsg) || !exampleType.isValid(&errMsg)) {
 
44
     *         // Can't use 'exampleType'. Take action.
 
45
     *     }
 
46
     *     // use 'exampleType'
 
47
     *
 
48
     */
 
49
    class ChunkType {
 
50
        MONGO_DISALLOW_COPYING(ChunkType);
 
51
    public:
 
52
 
 
53
        //
 
54
        // schema declarations
 
55
        //
 
56
 
 
57
        // Name of the chunks collection in the config server.
 
58
        static const std::string ConfigNS;
 
59
 
 
60
        // Field names and types in the chunks collection type.
 
61
        static const BSONField<std::string> name;
 
62
        static const BSONField<std::string> ns;
 
63
        static const BSONField<BSONObj> min;
 
64
        static const BSONField<BSONObj> max;
 
65
        static const BSONField<BSONArray> version;
 
66
        static const BSONField<std::string> shard;
 
67
        static const BSONField<bool> jumbo;
 
68
        static const BSONField<Date_t> DEPRECATED_lastmod;
 
69
        static const BSONField<OID> DEPRECATED_epoch;
 
70
 
 
71
        //
 
72
        // chunks type methods
 
73
        //
 
74
 
 
75
        ChunkType();
 
76
        ~ChunkType();
 
77
 
 
78
        /**
 
79
         * Returns true if all the mandatory fields are present and have valid
 
80
         * representations. Otherwise returns false and fills in the optional 'errMsg' string.
 
81
         */
 
82
        bool isValid(std::string* errMsg) const;
 
83
 
 
84
        /**
 
85
         * Returns the BSON representation of the entry.
 
86
         */
 
87
        BSONObj toBSON() const;
 
88
 
 
89
        /**
 
90
         * Clears and populates the internal state using the 'source' BSON object if the
 
91
         * latter contains valid values. Otherwise sets errMsg and returns false.
 
92
         */
 
93
        bool parseBSON(const BSONObj& source, std::string* errMsg);
 
94
 
 
95
        /**
 
96
         * Clears the internal state.
 
97
         */
 
98
        void clear();
 
99
 
 
100
        /**
 
101
         * Copies all the fields present in 'this' to 'other'.
 
102
         */
 
103
        void cloneTo(ChunkType* other) const;
 
104
 
 
105
        /**
 
106
         * Returns a string representation of the current internal state.
 
107
         */
 
108
        std::string toString() const;
 
109
 
 
110
        //
 
111
        // individual field accessors
 
112
        //
 
113
 
 
114
        // Mandatory Fields
 
115
        void setName(const StringData& name) {
 
116
            _name = name.toString();
 
117
            _isNameSet = true;
 
118
        }
 
119
 
 
120
        void unsetName() { _isNameSet = false; }
 
121
 
 
122
        bool isNameSet() const { return _isNameSet; }
 
123
 
 
124
        // Calling get*() methods when the member is not set results in undefined behavior
 
125
        const std::string getName() const {
 
126
            dassert(_isNameSet);
 
127
            return _name;
 
128
        }
 
129
 
 
130
        void setNS(const StringData& ns) {
 
131
            _ns = ns.toString();
 
132
            _isNsSet = true;
 
133
        }
 
134
 
 
135
        void unsetNS() { _isNsSet = false; }
 
136
 
 
137
        bool isNSSet() const { return _isNsSet; }
 
138
 
 
139
        // Calling get*() methods when the member is not set results in undefined behavior
 
140
        const std::string getNS() const {
 
141
            dassert(_isNsSet);
 
142
            return _ns;
 
143
        }
 
144
 
 
145
        void setMin(const BSONObj& min) {
 
146
            _min = min.getOwned();
 
147
            _isMinSet = true;
 
148
        }
 
149
 
 
150
        void unsetMin() { _isMinSet = false; }
 
151
 
 
152
        bool isMinSet() const { return _isMinSet; }
 
153
 
 
154
        // Calling get*() methods when the member is not set results in undefined behavior
 
155
        const BSONObj getMin() const {
 
156
            dassert(_isMinSet);
 
157
            return _min;
 
158
        }
 
159
 
 
160
        void setMax(const BSONObj& max) {
 
161
            _max = max.getOwned();
 
162
            _isMaxSet = true;
 
163
        }
 
164
 
 
165
        void unsetMax() { _isMaxSet = false; }
 
166
 
 
167
        bool isMaxSet() const { return _isMaxSet; }
 
168
 
 
169
        // Calling get*() methods when the member is not set results in undefined behavior
 
170
        const BSONObj getMax() const {
 
171
            dassert(_isMaxSet);
 
172
            return _max;
 
173
        }
 
174
 
 
175
        void setVersion(const ChunkVersion& version) {
 
176
            _version = version;
 
177
            _isVersionSet = true;
 
178
        }
 
179
 
 
180
        void unsetVersion() { _isVersionSet = false; }
 
181
 
 
182
        bool isVersionSet() const { return _isVersionSet; }
 
183
 
 
184
        // Calling get*() methods when the member is not set results in undefined behavior
 
185
        const ChunkVersion& getVersion() const {
 
186
            dassert(_isVersionSet);
 
187
            return _version;
 
188
        }
 
189
 
 
190
        void setShard(const StringData& shard) {
 
191
            _shard = shard.toString();
 
192
            _isShardSet = true;
 
193
        }
 
194
 
 
195
        void unsetShard() { _isShardSet = false; }
 
196
 
 
197
        bool isShardSet() const { return _isShardSet; }
 
198
 
 
199
        // Calling get*() methods when the member is not set results in undefined behavior
 
200
        const std::string getShard() const {
 
201
            dassert(_isShardSet);
 
202
            return _shard;
 
203
        }
 
204
 
 
205
        // Optional Fields
 
206
        void setJumbo(bool jumbo) {
 
207
            _jumbo = jumbo;
 
208
            _isJumboSet = true;
 
209
        }
 
210
 
 
211
        void unsetJumbo() { _isJumboSet = false; }
 
212
 
 
213
        bool isJumboSet() const {
 
214
            return _isJumboSet || jumbo.hasDefault();
 
215
        }
 
216
 
 
217
        // Calling get*() methods when the member is not set and has no default results in undefined
 
218
        // behavior
 
219
        bool getJumbo() const {
 
220
            if (_isJumboSet) {
 
221
                return _jumbo;
 
222
            } else {
 
223
                dassert(jumbo.hasDefault());
 
224
                return jumbo.getDefault();
 
225
            }
 
226
        }
 
227
 
 
228
    private:
 
229
        // Convention: (M)andatory, (O)ptional, (S)pecial rule.
 
230
        std::string _name;     // (M)  chunk's id
 
231
        bool _isNameSet;
 
232
        std::string _ns;     // (M)  collection this chunk is in
 
233
        bool _isNsSet;
 
234
        BSONObj _min;     // (M)  first key of the range, inclusive
 
235
        bool _isMinSet;
 
236
        BSONObj _max;     // (M)  last key of the range, non-inclusive
 
237
        bool _isMaxSet;
 
238
        ChunkVersion _version;     // (M)  version of this chunk
 
239
        bool _isVersionSet;
 
240
        std::string _shard;     // (M)  shard this chunk lives in
 
241
        bool _isShardSet;
 
242
        bool _jumbo;     // (O)  too big to move?
 
243
        bool _isJumboSet;
 
244
    };
 
245
 
 
246
} // namespace mongo