~ubuntu-branches/ubuntu/trusty/mongodb/trusty-proposed

« back to all changes in this revision

Viewing changes to db/database.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Antonin Kral
  • Date: 2010-01-29 19:48:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100129194845-8wbmkf626fwcavc9
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// database.cpp
 
2
 
 
3
/**
 
4
*    Copyright (C) 2008 10gen Inc.
 
5
*
 
6
*    This program is free software: you can redistribute it and/or  modify
 
7
*    it under the terms of the GNU Affero General Public License, version 3,
 
8
*    as published by the Free Software Foundation.
 
9
*
 
10
*    This program is distributed in the hope that it will be useful,
 
11
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
*    GNU Affero General Public License for more details.
 
14
*
 
15
*    You should have received a copy of the GNU Affero General Public License
 
16
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#include "stdafx.h"
 
20
#include "pdfile.h"
 
21
#include "database.h"
 
22
 
 
23
namespace mongo {
 
24
 
 
25
    bool Database::_openAllFiles = false;
 
26
 
 
27
    bool Database::setProfilingLevel( int newLevel , string& errmsg ){
 
28
        if ( profile == newLevel )
 
29
            return true;
 
30
        
 
31
        if ( newLevel < 0 || newLevel > 2 ){
 
32
            errmsg = "profiling level has to be >=0 and <= 2";
 
33
            return false;
 
34
        }
 
35
        
 
36
        if ( newLevel == 0 ){
 
37
            profile = 0;
 
38
            return true;
 
39
        }
 
40
        
 
41
        assert( cc().database() == this );
 
42
 
 
43
        if ( ! namespaceIndex.details( profileName.c_str() ) ){
 
44
            log(1) << "creating profile ns: " << profileName << endl;
 
45
            BSONObjBuilder spec;
 
46
            spec.appendBool( "capped", true );
 
47
            spec.append( "size", 131072.0 );
 
48
            if ( ! userCreateNS( profileName.c_str(), spec.done(), errmsg , true ) ){
 
49
                return false;
 
50
            }
 
51
        }
 
52
        profile = newLevel;
 
53
        return true;
 
54
    }
 
55
 
 
56
    void Database::finishInit(){
 
57
        if ( cmdLine.defaultProfile == profile )
 
58
            return;
 
59
        
 
60
        string errmsg;
 
61
        massert( 12506 , errmsg , setProfilingLevel( cmdLine.defaultProfile , errmsg ) );
 
62
    }
 
63
 
 
64
} // namespace mongo