Skip to content

Commit

Permalink
simple quotas for disk usage
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown authored and unknown committed Dec 27, 2008
1 parent d3d8cb5 commit 4148938
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
12 changes: 9 additions & 3 deletions db/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,20 @@ class Database {
files.push_back(0);
PhysicalDataFile* p = files[n];
if( p == 0 ) {
p = new PhysicalDataFile(n);
files[n] = p;
stringstream ss;
ss << name << '.' << n;
boost::filesystem::path fullName;
fullName = boost::filesystem::path(path) / ss.str();
string fullNameString = fullName.string();
p->open(n, fullNameString.c_str() );
p = new PhysicalDataFile(n);
try {
p->open(n, fullNameString.c_str() );
}
catch( AssertionException& u ) {
delete p;
throw u;
}
files[n] = p;
}
return p;
}
Expand Down
8 changes: 4 additions & 4 deletions db/db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "dbmessage.h"
#include "instance.h"

extern bool objcheck, quiet, quotasimple;
extern bool objcheck, quiet, quota;
bool useJNI = true;

/* only off if --nocursors which is for debugging. */
Expand Down Expand Up @@ -438,8 +438,8 @@ int main(int argc, char* argv[], char *envp[] )
goto usage;
else if( s == "--quiet" )
quiet = true;
else if( s == "--quotasimple" )
quotasimple = true;
else if( s == "--quota" )
quota = true;
else if( s == "--objcheck" )
objcheck = true;
else if( s == "--source" ) {
Expand Down Expand Up @@ -490,7 +490,7 @@ int main(int argc, char* argv[], char *envp[] )
cout << " --dbpath <root> directory for datafiles, default is /data/db/\n";
cout << " --quiet quieter output (no cpu outputs)\n";
cout << " --objcheck inspect client data for validity on receipt\n";
cout << " --quotasimple apply simple quotas to use of the db\n";
cout << " --quota enable db quota management\n";
cout << " --appsrvpath <path> root directory for the babble app server\n";
cout << " --nocursors diagnostic/debugging option\n";
cout << " --nojni" << endl;
Expand Down
13 changes: 8 additions & 5 deletions db/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@
#include "dbmessage.h"
#include "instance.h"

int nloggedsome = 0;
#define LOGSOME if( ++nloggedsome < 1000 || nloggedsome % 100 == 0 )

bool objcheck = false;
bool quotasimple = false;
bool quota = false;
bool slave = false;
bool master = false; // true means keep an op log
extern int curOp;
Expand Down Expand Up @@ -111,7 +114,7 @@ bool assembleResponse( Message &m, DbResponse &dbresponse ) {
receivedInsert(m, ss);
}
catch( AssertionException& e ) {
problem() << " Caught Assertion insert, continuing\n";
LOGSOME problem() << " Caught Assertion insert, continuing\n";
ss << " exception " + e.toString();
}
}
Expand All @@ -122,7 +125,7 @@ bool assembleResponse( Message &m, DbResponse &dbresponse ) {
receivedUpdate(m, ss);
}
catch( AssertionException& e ) {
problem() << " Caught Assertion update, continuing" << endl;
LOGSOME problem() << " Caught Assertion update, continuing" << endl;
ss << " exception " + e.toString();
}
}
Expand All @@ -133,7 +136,7 @@ bool assembleResponse( Message &m, DbResponse &dbresponse ) {
receivedDelete(m);
}
catch( AssertionException& e ) {
problem() << " Caught Assertion receivedDelete, continuing" << endl;
LOGSOME problem() << " Caught Assertion receivedDelete, continuing" << endl;
ss << " exception " + e.toString();
}
}
Expand Down Expand Up @@ -263,7 +266,7 @@ void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, *
}
catch( AssertionException& e ) {
ss << " exception ";
problem() << " Caught Assertion in runQuery ns:" << q.ns << ' ' << e.toString() << '\n';
LOGSOME problem() << " Caught Assertion in runQuery ns:" << q.ns << ' ' << e.toString() << '\n';
log() << " ntoskip:" << q.ntoskip << " ntoreturn:" << q.ntoreturn << '\n';
if( q.query.valid() )
log() << " query:" << q.query.toString() << endl;
Expand Down
22 changes: 20 additions & 2 deletions db/pdfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ _ disallow system* manipulations from the database.
#include "query.h"
#include "repl.h"

extern bool quota;
extern int port;

const char *dbpath = "/data/db/";
Expand Down Expand Up @@ -156,6 +157,24 @@ bool userCreateNS(const char *ns, BSONObj j, string& err, bool logForReplication
/*---------------------------------------------------------------------*/

void PhysicalDataFile::open(int fn, const char *filename) {
{
/* check quotas
very simple temporary implementation - we will in future look up
the quota from the grid database
*/
if( quota && fn > 8 && !boost::filesystem::exists(filename) ) {
/* todo: if we were adding / changing keys in an index did we do some
work previously that needs cleaning up? Possible. We should
check code like that and have it catch the exception and do
something reasonable.
*/
string s = "db disk space quota exceeded ";
if( database )
s += database->name;
uasserted(s.c_str());
}
}

int length;

if( fn <= 4 ) {
Expand All @@ -168,10 +187,9 @@ void PhysicalDataFile::open(int fn, const char *filename) {
} else
length = 0x7ff00000;

if ( sizeof( int* ) == 4 && fn > 4 )
if ( sizeof( int* ) == 4 && fn > 4 )
length = 512 * 1024 * 1024;


assert( length >= 64*1024*1024 );

if( strstr(filename, "_hudsonSmall") ) {
Expand Down
6 changes: 5 additions & 1 deletion stdafx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ void asserted(const char *msg, const char *file, unsigned line) {
throw AssertionException();
}

int uacount = 0;
void uasserted(const char *msg) {
problem() << "User Assertion " << msg << endl;
if( ++uacount < 100 )
problem() << "User Assertion " << msg << endl;
else
RARELY problem() << "User Assertion " << msg << endl;
lastAssert[3].set(msg, getDbContext().c_str(), "", 0);
throw UserAssertionException(msg);
}
Expand Down

0 comments on commit 4148938

Please sign in to comment.