<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 02:58:41 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[SERVER-2005] Integer overflow with upsert</title>
                <link>https://jira.mongodb.org/browse/SERVER-2005</link>
                <project id="10000" key="SERVER">Core Server</project>
                    <description>&lt;p&gt;I&apos;m having an issue that I can only assume is a 32-bit integer overflow issue.  I&apos;m running on 64-bit Linux boxes with the 64-bit builds of MongoDB v1.6.3.&lt;/p&gt;

&lt;p&gt;Here&apos;s the deal:&lt;/p&gt;

&lt;p&gt;I have a collection used for logging and aggregate counters.  I&apos;m using an upsert with $inc to increment these counters.  When the counters get over 2^31, it rolls over to negative.&lt;/p&gt;

&lt;p&gt;I&apos;ve been able to reproduce it with the ruby driver:&lt;/p&gt;

&lt;p&gt;require &apos;rubygems&apos;&lt;br/&gt;
require &apos;mongo&apos;&lt;/p&gt;

&lt;p&gt;mongo = Mongo::Connection.new &quot;localhost&quot;&lt;br/&gt;
db = mongo.db &quot;test&quot;&lt;/p&gt;

&lt;p&gt;db.collection(&apos;junk&apos;).drop&lt;br/&gt;
(0..20).each do |i|&lt;br/&gt;
  db.collection(&apos;junk&apos;).update({:name=&amp;gt;&apos;luke&apos;}, {&quot;$inc&quot;=&amp;gt;{:total=&amp;gt;123456789}}, {:upsert=&amp;gt;true})&lt;br/&gt;
  puts db.collection(&apos;junk&apos;).find({}, {:fields=&amp;gt;{:_id=&amp;gt;0}}).to_a.inspect&lt;br/&gt;
end&lt;/p&gt;

&lt;p&gt;and that outputs: (I&apos;ve bolded the line where it flips negative)&lt;/p&gt;

&lt;p&gt;[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;123456789}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;246913578}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;370370367}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;493827156}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;617283945}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;740740734}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;864197523}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;987654312}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1111111101}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1234567890}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1358024679}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1481481468}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1604938257}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1728395046}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1851851835}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;1975308624}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;2098765413}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;-2072745094}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;-1949288305}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;-1825831516}
&lt;p&gt;]&lt;br/&gt;
[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;-1702374727}
&lt;p&gt;]&lt;/p&gt;


&lt;p&gt;I suspect that initially MongoDB is storing the integer using the 4-byte integer data type, but when my upsert increments it, it isn&apos;t converted to the 8-byte integer.&lt;/p&gt;

&lt;p&gt;Just for fun, I tried upserting a large number and it indeed is stored just fine (I suspect it is created as an 8-byte integer):&lt;/p&gt;

&lt;p&gt;db.collection(&apos;junk&apos;).drop&lt;br/&gt;
db.collection(&apos;junk&apos;).update({:name=&amp;gt;&apos;luke&apos;}, {&quot;$inc&quot;=&amp;gt;{:total=&amp;gt;9999999999999}}, {:upsert=&amp;gt;true})&lt;br/&gt;
puts db.collection(&apos;junk&apos;).find({}, {:fields=&amp;gt;{:_id=&amp;gt;0}}).to_a.inspect&lt;/p&gt;

&lt;p&gt;and that outputs (which is clearly an 8-byte integer):&lt;/p&gt;

&lt;p&gt;[&lt;/p&gt;
{&quot;name&quot;=&amp;gt;&quot;luke&quot;, &quot;total&quot;=&amp;gt;9999999999999}
&lt;p&gt;]&lt;/p&gt;</description>
                <environment>MongoDB v1.6.3, 64-bit builds on 64-bit Linux (Ubuntu 10.4)</environment>
        <key id="13505">SERVER-2005</key>
            <summary>Integer overflow with upsert</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="lehresman">Luke Ehresman</reporter>
                        <labels>
                    </labels>
                <created>Mon, 25 Oct 2010 22:16:53 +0000</created>
                <updated>Tue, 12 Jul 2016 00:19:35 +0000</updated>
                            <resolved>Tue, 2 Nov 2010 03:38:58 +0000</resolved>
                                    <version>1.6.3</version>
                                    <fixVersion>1.7.3</fixVersion>
                                    <component>Write Ops</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="19999" author="nehresma" created="Wed, 3 Nov 2010 14:54:49 +0000"  >&lt;p&gt;The documentation should be changed on the following link:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It currently says &quot;This is most important when doing a find-and-update loop that changes the size of documents that are returned ($inc does not change size).&quot;  With the fix on this ticket, it is no longer true that $inc does not change the BSON document size.&lt;/p&gt;</comment>
                            <comment id="19950" author="auto" created="Tue, 2 Nov 2010 03:38:56 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: fix $inc overflow on int &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2005&quot; title=&quot;Integer overflow with upsert&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2005&quot;&gt;&lt;del&gt;SERVER-2005&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo/commit/2dd5f90b5d2ae403abbf895316f08262600df380&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo/commit/2dd5f90b5d2ae403abbf895316f08262600df380&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="19647" author="eliot" created="Tue, 26 Oct 2010 12:45:28 +0000"  >&lt;p&gt;Once fixed - when it needs to overflow - the size will have to change as it will go from int to long&lt;/p&gt;</comment>
                            <comment id="19646" author="nehresma" created="Tue, 26 Oct 2010 12:42:35 +0000"  >&lt;p&gt;Will this affect query snapshots?  According to the link below, $inc wont change the document size:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="19645" author="auto" created="Tue, 26 Oct 2010 11:58:00 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;login&apos;: &apos;erh&apos;, &apos;name&apos;: &apos;Eliot Horowitz&apos;, &apos;email&apos;: &apos;eliot@10gen.com&apos;}
&lt;p&gt;Message: test for &lt;a href=&quot;https://jira.mongodb.org/browse/SERVER-2005&quot; title=&quot;Integer overflow with upsert&quot; class=&quot;issue-link&quot; data-issue-key=&quot;SERVER-2005&quot;&gt;&lt;del&gt;SERVER-2005&lt;/del&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href=&quot;http://github.com/mongodb/mongo/commit/4e5c46df588084198a777d34e18c62de2910ca72&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;http://github.com/mongodb/mongo/commit/4e5c46df588084198a777d34e18c62de2910ca72&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>5.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Tue, 26 Oct 2010 11:58:00 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        13 years, 16 weeks ago
    
                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_18254" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Dependencies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue><![CDATA[]]></customfieldvalue>


                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_10057" key="com.atlassian.jira.toolkit:lastusercommented">
                        <customfieldname>Last comment by Customer</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>true</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_10056" key="com.atlassian.jira.toolkit:lastupdaterorcommenter">
                        <customfieldname>Last commenter</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>ramon.fernandez@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            13 years, 16 weeks ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Old_Backport</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10000"><![CDATA[No]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10032" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Operating System</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10026"><![CDATA[ALL]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>auto</customfieldvalue>
            <customfieldvalue>eliot</customfieldvalue>
            <customfieldvalue>lehresman</customfieldvalue>
            <customfieldvalue>nehresma</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrpchz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrigov:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>21356</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                            <customfield id="customfield_23361" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Requested By</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_22870" key="com.onresolve.jira.groovy.groovyrunner:scripted-field">
                        <customfieldname>Triagers</customfieldname>
                        <customfieldvalues>
                                

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrs3qf:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                    </customfields>
    </item>
</channel>
</rss>