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

« back to all changes in this revision

Viewing changes to src/mongo/db/database.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:
16
16
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
17
*/
18
18
 
19
 
#include "pch.h"
20
 
#include "pdfile.h"
21
 
#include "database.h"
22
 
#include "instance.h"
23
 
#include "introspect.h"
24
 
#include "clientcursor.h"
25
 
#include "databaseholder.h"
 
19
#include "mongo/pch.h"
 
20
 
 
21
#include "mongo/db/database.h"
26
22
 
27
23
#include <boost/filesystem/operations.hpp>
28
24
 
 
25
#include "mongo/db/auth/auth_index_d.h"
 
26
#include "mongo/db/clientcursor.h"
 
27
#include "mongo/db/databaseholder.h"
 
28
#include "mongo/db/instance.h"
 
29
#include "mongo/db/introspect.h"
 
30
#include "mongo/db/pdfile.h"
 
31
 
29
32
namespace mongo {
30
33
 
31
 
    bool Database::_openAllFiles = true;
32
 
 
33
34
    void assertDbAtLeastReadLocked(const Database *db) { 
34
35
        if( db ) { 
35
36
            Lock::assertAtLeastReadLocked(db->name);
88
89
#endif
89
90
            }
90
91
            newDb = namespaceIndex.exists();
91
 
            profile = cmdLine.defaultProfile;
 
92
            _profile = cmdLine.defaultProfile;
92
93
            checkDuplicateUncasedNames(true);
93
94
            // If already exists, open.  Otherwise behave as if empty until
94
95
            // there's a write, then open.
95
96
            if (!newDb) {
96
97
                namespaceIndex.init();
97
 
                if( _openAllFiles )
98
 
                    openAllFiles();
 
98
                openAllFiles();
99
99
            }
100
100
            magic = 781231;
101
101
        } catch(std::exception& e) {
231
231
        }
232
232
    }
233
233
 
 
234
    void Database::clearTmpCollections() {
 
235
 
 
236
        Lock::assertWriteLocked( name );
 
237
        Client::Context ctx( name );
 
238
 
 
239
        string systemNamespaces =  name + ".system.namespaces";
 
240
 
 
241
        // Note: we build up a toDelete vector rather than dropping the collection inside the loop
 
242
        // to avoid modifying the system.namespaces collection while iterating over it since that
 
243
        // would corrupt the cursor.
 
244
        vector<string> toDelete;
 
245
        shared_ptr<Cursor> cursor = theDataFileMgr.findAll(systemNamespaces);
 
246
        while ( cursor && cursor->ok() ) {
 
247
            BSONObj nsObj = cursor->current();
 
248
            cursor->advance();
 
249
 
 
250
            BSONElement e = nsObj.getFieldDotted( "options.temp" );
 
251
            if ( !e.trueValue() )
 
252
                continue;
 
253
 
 
254
            string ns = nsObj["name"].String();
 
255
 
 
256
            // Do not attempt to drop indexes
 
257
            if ( !NamespaceString::normal(ns.c_str()) )
 
258
                continue;
 
259
 
 
260
            toDelete.push_back(ns);
 
261
        }
 
262
 
 
263
        for (size_t i=0; i < toDelete.size(); i++) {
 
264
            const string& ns = toDelete[i];
 
265
 
 
266
            string errmsg;
 
267
            BSONObjBuilder result;
 
268
            dropCollection(ns, errmsg, result);
 
269
 
 
270
            if ( errmsg.size() > 0 ) {
 
271
                warning() << "could not delete temp collection: " << ns
 
272
                          << " because of: " << errmsg << endl;
 
273
            }
 
274
        }
 
275
    }
 
276
 
234
277
    // todo: this is called a lot. streamline the common case
235
278
    MongoDataFile* Database::getFile( int n, int sizeNeeded , bool preallocateOnly) {
236
279
        verify(this);
253
296
                if( !Lock::isWriteLocked(this->name) ) {
254
297
                    log() << "error: getFile() called in a read lock, yet file to return is not yet open" << endl;
255
298
                    log() << "       getFile(" << n << ") _files.size:" <<_files.size() << ' ' << fileName(n).string() << endl;
256
 
                    log() << "       context ns: " << cc().ns() << " openallfiles:" << _openAllFiles << endl;
 
299
                    log() << "       context ns: " << cc().ns() << endl;
257
300
                    verify(false);
258
301
                }
259
302
                _files.push_back(0);
364
407
 
365
408
 
366
409
    bool Database::setProfilingLevel( int newLevel , string& errmsg ) {
367
 
        if ( profile == newLevel )
 
410
        if ( _profile == newLevel )
368
411
            return true;
369
412
 
370
413
        if ( newLevel < 0 || newLevel > 2 ) {
373
416
        }
374
417
 
375
418
        if ( newLevel == 0 ) {
376
 
            profile = 0;
 
419
            _profile = 0;
377
420
            return true;
378
421
        }
379
422
 
380
423
        verify( cc().database() == this );
381
424
 
382
 
        if (!getOrCreateProfileCollection(this, true))
 
425
        if (!getOrCreateProfileCollection(this, true, &errmsg))
383
426
            return false;
384
427
 
385
 
        profile = newLevel;
 
428
        _profile = newLevel;
386
429
        return true;
387
430
    }
388
431
 
434
477
            massert(15927, "can't open database in a read lock. if db was just closed, consider retrying the query. might otherwise indicate an internal error", !cant);
435
478
        }
436
479
 
 
480
        // we mark our thread as having done writes now as we do not want any exceptions
 
481
        // once we start creating a new database
 
482
        cc().writeHappened();
 
483
 
437
484
        // this locks _m for defensive checks, so we don't want to be locked right here : 
438
485
        Database *db = new Database( dbname.c_str() , justCreated , path );
439
486
 
445
492
            _size++;
446
493
        }
447
494
 
 
495
        authindex::configureSystemIndexes(dbname);
 
496
 
 
497
        db->clearTmpCollections();
 
498
 
448
499
        return db;
449
500
    }
450
501