Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-8311

usePowerOf2Sizes rounds already quantized values to next highest quantum level

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.7.1
    • Affects Version/s: None
    • Component/s: Storage
    • None
    • Fully Compatible

      If NamespaceDetails::getRecordAllocationSize() is passed a value that is a power of 2, and Flag_UsePowerOf2Sizes is enabled, the function will return the next power of two (or the next 1mb increment if >= 4mb).

      This is only an issue in (potentially rare) cases when getRecordAllocationSize() is passed a value that is already quantized.

      Test

      c = db.c;
      
      
      c.drop();
      db.createCollection( 'c' );
      printjson( db.runCommand( { collMod:'c', usePowerOf2Sizes:true } ) );
      
      big = new Array( 1024 * 1024 - 41 ).toString();
      doc = { _id:0, b:big };
      assert.eq( 0x100000 - 0x10, Object.bsonsize( doc ) );
      
      // A doc of size 0x100000 - 0x10 triggers a record allocation request of size 0x100000.                              
      c.insert( doc );
      
      // But the actual record size allocated is 0x200000.  This can be seen by adding logging.                            
      printjson( c.dataSize() ); // 0x200000 - 0x10                                                                        
      
      
      c.drop();
      db.createCollection( 'c' );
      printjson( db.runCommand( { collMod:'c', usePowerOf2Sizes:true } ) );
      
      big = new Array( 16 * 1024 * 1024 - 41 ).toString();
      doc = { _id:0, b:big };
      assert.eq( 0x1000000 - 0x10, Object.bsonsize( doc ) );
      // A doc of size 0x1000000 - 0x10 triggers a record allocation request of size 0x1000000.                            
      c.insert( doc );
      
      // But the actual record size allocated is 0x1100000.  This can be seen by adding logging.                           
      printjson( c.dataSize() ); // 0x1100000 - 0x10                                     
      

            Assignee:
            mathias@mongodb.com Mathias Stearn
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: