[SERVER-5034] strange object behavior in v8 shell Created: 22/Feb/12  Updated: 11/Jul/16  Resolved: 27/Feb/12

Status: Closed
Project: Core Server
Component/s: JavaScript
Affects Version/s: None
Fix Version/s: 2.1.1

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Antoine Girbal
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-5108 find7.js is failing in V8 build Linux 64 Closed
Operating System: ALL
Participants:

 Description   

When I run the following script, the v8 shell seems to think the "nscanned" field of the returned document is undefined. But if I printjson the document first (see commented line), the proper nscanned field is found. This seems to occur in the v8 shell only (not the sm shell).

git version ab7b4dbb51ac7252ecf4a3525ead615ecc243bdb

 
t = db.jstests_explain4;
t.drop();
 
function checkField( name, value, explain ) {
    assert.eq( value, explain[ name ], name );
}
 
explain = t.find().explain( true );
//printjson( explain );                                                                                                                       
 
checkField( "cursor", "BasicCursor", explain );
checkField( "n", 0, explain );
checkField( "nscannedObjects", 0, explain );
checkField( "indexBounds", {}, explain );
checkField( "nscanned", 0, explain );
 

Note the above test is a simplified version of my original test which had this issue. If you can't reproduce I can provide the original test.



 Comments   
Comment by auto [ 07/Mar/12 ]

Author:

{u'login': u'astaple', u'email': u'aaron@10gen.com', u'name': u'Aaron'}

Message: SERVER-5034 reinstate tests in v8 mode
Branch: master
https://github.com/mongodb/mongo/commit/4cd88bf3117d4a29c95bfc3c62f0580b71201408

Comment by Antoine Girbal [ 27/Feb/12 ]

Looks like setting key values to 'undefined' confuses the callbacks into C++.
Reworked the handling of keys to avoid use of undefined.

Comment by auto [ 27/Feb/12 ]

Author:

{u'login': u'agirbal', u'name': u'agirbal', u'email': u'antoine@10gen.com'}

Message: SERVER-5034: strange object behavior in v8 shell, reworked wrapper handling of keys
Branch: master
https://github.com/mongodb/mongo/commit/10da27ca707b6b7b2766f4b4210ceb273da5dfdc

Comment by Antoine Girbal [ 27/Feb/12 ]

This issue is extremely odd.
From your example, it's always the 5th field request that fails.
If only 4 fields are accessed, there is no undefined.

Did also the following test.

> checkField
function checkField( name, value, explain ) {
    assert.eq( value, explain[ name ], name );
}
 
> var explain = db.foo.find().explain()
> checkField( "n", 0, explain );
assert: [0] != [undefined] are not equal : n
Error: Printing Stack Trace
    at src/mongo/shell/utils.js:37:7
    at src/mongo/shell/utils.js:58:1
    at Function.eq (src/mongo/shell/utils.js:84:1)
    at checkField ((shell):2:12)
    at (shell):1:21
Sun Feb 26 16:21:25 exec error: (shell):0 [0] != [undefined] are not equal : n
 
^

Now same with just a function that prints, no issue:

> var explain = db.foo.find().explain()
> myprint
function ( name, value, explain) { print(explain[name]); print(value);}
> myprint( "n", 0, explain );
NumberLong(0)
0

Trying with some debug prints, it appears that the named accessor in v8 wrapper is not called for that property.
It's as if there is some v8 optim that breaks custom access to properties.
Will try with older versions of v8 see if it always happened.

Comment by auto [ 25/Feb/12 ]

Author:

{u'login': u'astaple', u'name': u'Aaron', u'email': u'aaron@10gen.com'}

Message: SERVER-5034 disable tests failing in v8 mode
Branch: master
https://github.com/mongodb/mongo/commit/4dd695bb9b0f2179477a114c26d314d4f4c015c1

Generated at Thu Feb 08 03:07:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.