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

Database store a value different to the one provided as 64 bits long integer

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 3.2.7
    • Labels:
      None
    • ALL
    • Hide

      In a MongoDB Linux installation, following the Instructions at MongoDB Docs
      Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

      In Linux shell run the MongoDB shell client:

      /usr/bin/mongo
      MongoDB shell version: 3.2.7
      connecting to: test
      >

      In the MongoDB shell client:

      use integers
      
      db.createCollection("sequences", {
         validator:
         {
            seq: { $type: "long" }
         },
         validationLevel: "strict",
         validationAction: "error"
      })
      
      db.sequences.insert(
         {  _id: "Seq1", seq: NumberLong(9223372036854775804) }
      )
      
      db.sequences.find()
      

      You can drop the collection and restart with a different number:

      db.sequences.drop()
      

      Here is a command line running sample:

      root@localhost:/# /usr/bin/mongo
      MongoDB shell version: 3.2.7
      connecting to: test
      >
      > use integers
      switched to db integers
      >
      > db.createCollection("sequences", {
      ...    validator:
      ...    {
      ...       seq: { $type: "long" }
      ...    },
      ...    validationLevel: "strict",
      ...    validationAction: "error"
      ... })
      { "ok" : 1 }
      >
      > db.sequences.insert(
      ...    {  _id: "Seq1", seq: NumberLong(9223372036854775804) }
      ... )
      WriteResult({ "nInserted" : 1 })
      >
      > db.sequences.find()
      { "_id" : "Seq1", "seq" : NumberLong("-9223372036854775808") }
      >
      >
      
      Show
      In a MongoDB Linux installation, following the Instructions at MongoDB Docs Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ In Linux shell run the MongoDB shell client: /usr/bin/mongo MongoDB shell version: 3.2.7 connecting to: test > In the MongoDB shell client: use integers db.createCollection( "sequences" , { validator: { seq: { $type: " long " } }, validationLevel: "strict" , validationAction: "error" }) db.sequences.insert( { _id: "Seq1" , seq: NumberLong(9223372036854775804) } ) db.sequences.find() You can drop the collection and restart with a different number: db.sequences.drop() Here is a command line running sample: root@localhost:/# /usr/bin/mongo MongoDB shell version: 3.2.7 connecting to: test > > use integers switched to db integers > > db.createCollection( "sequences" , { ... validator: ... { ... seq: { $type: " long " } ... }, ... validationLevel: "strict" , ... validationAction: "error" ... }) { "ok" : 1 } > > db.sequences.insert( ... { _id: "Seq1" , seq: NumberLong(9223372036854775804) } ... ) WriteResult({ "nInserted" : 1 }) > > db.sequences.find() { "_id" : "Seq1" , "seq" : NumberLong( "-9223372036854775808" ) } > >

      Please, reroute me if this has a workaround for 64 bits, data handling (can't afford bits modifications by the database, or the database interface)

      When using the mongo shell client in Linux, storing a 64 bits long integer result in a stored value different in more than 60 bits.
      Is unknown if the problem is a client error, a database error or a data handling error.

      Storing .. 9223372036854775804 (0x7FFFFFFFFFFFFFFC)
      Stored .. -9223372036854775808 (0x8000000000000000)
      62 bits differs

      Storing .. 4611686018427387900 (0x3FFFFFFFFFFFFFFC)
      Stored ... 4611686018427387904 (0x4000000000000000)
      61 bits differs

      Storing .. 2305843009213693951 (0x1FFFFFFFFFFFFFFF)
      Stored ... 2305843009213693952 (0x2000000000000000)
      62 bits differs

      Storing .. 1152921504606846975 (0x0FFFFFFFFFFFFFFF)
      Stored ... 1152921504606846976 (0x1000000000000000)
      61 bits differs

      Storing ... 576460752303423487 (0x07FFFFFFFFFFFFFF)
      Stored .... 576460752303423488 (0x0800000000000000)
      60 bits differs

      Storing ... 288230376151711743 (0x03FFFFFFFFFFFFFF)
      Stored .... 288230376151711744 (0x0400000000000000)
      59 bits differs

      I manage to pin point the border of the problem, when the bit 52 is on, the minor bits appears to be rounded (This make match with the 53 bits of mantissa for the IEEE 754 64 bit double precision floating point), the maximum number assignable (in case of restart, with initialization) is: 9,007,199,254,740,991

      Storing ...... 9007199254740991 (0x001FFFFFFFFFFFFF)
      Stored ....... 9007199254740991 (0x001FFFFFFFFFFFFF)
      NO bits differs

            Assignee:
            Unassigned Unassigned
            Reporter:
            TrustworthySystems TrustworthySystems [X]
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: