Permalink
Browse files

Don't insert oversized records into system.profile SERVER-3618

  • Loading branch information...
1 parent c7af2b9 commit 912924dd7029eedf88e8314ad90bed0a94ba0e14 @RedBeard0531 RedBeard0531 committed Aug 16, 2011
Showing with 39 additions and 0 deletions.
  1. +20 −0 db/introspect.cpp
  2. +19 −0 jstests/profile2.js
View
@@ -49,6 +49,26 @@ namespace mongo {
BSONObj p = b.done();
+ if (p.objsize() > 100*1024){
+ string small = p.toString(/*isArray*/false, /*full*/false);
+
+ warning() << "can't add full line to system.profile: " << small;
+
+ // rebuild with limited info
+ BSONObjBuilder b(profileBufBuilder);
+ b.appendDate("ts", jsTime());
+ b.append("client", c.clientAddress() );
+ if ( c.getAuthenticationInfo() )
+ b.append( "user" , c.getAuthenticationInfo()->getUser( nsToDatabase( ns ) ) );
+
+ b.append("err", "profile line too large (max is 100KB)");
+ if (small.size() < 100*1024){ // should be much smaller but if not don't break anything
+ b.append("abbreviated", small);
+ }
+
+ p = b.done();
+ }
+
// write: not replicated
NamespaceDetails *d = db->namespaceIndex.details(ns);
if( d ) {
View
@@ -0,0 +1,19 @@
+print("profile2.js BEGIN");
+
+try {
+
+ assert.commandWorked( db.runCommand( {profile:2} ) );
+
+ huge = 'huge';
+ while (huge.length < 2*1024*1024){
+ huge += huge;
+ }
+
+ db.profile2.count({huge:huge}) // would make a huge entry in db.system.profile
+
+ print("profile2.js SUCCESS OK");
+
+} finally {
+ // disable profiling for subsequent tests
+ assert.commandWorked( db.runCommand( {profile:0} ) );
+}

0 comments on commit 912924d

Please sign in to comment.