<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 07:56:27 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>[DOCS-8512] Primary Shard of new Database is Shard with least data on it</title>
                <link>https://jira.mongodb.org/browse/DOCS-8512</link>
                <project id="10380" key="DOCS">Documentation</project>
                    <description>&lt;p&gt;This question comes up once in a while. When a new database is created in a sharded cluster, which shard is chosen as the &quot;primary shard&quot;. I have seen answers from support saying &quot;round robin&quot; and &quot;arbitrary&quot;. The answer according to SERVER team is that the shard with the least amount of data on it is picked as the &quot;primary shard&quot; for the new database. At least since 2.0, unsure of earlier versions.&lt;/p&gt;

&lt;p&gt;Our education clases m102 says its the first shard always. m202 says random.&lt;/p&gt;

&lt;p&gt;Documentation doesn&apos;t mention this at all at docs.mongodb.com.&lt;/p&gt;</description>
                <environment></environment>
        <key id="306825">DOCS-8512</key>
            <summary>Primary Shard of new Database is Shard with least data on it</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="ravind.kumar">Ravind Kumar</assignee>
                                    <reporter username="roy.rim@mongodb.com">Roy Rim</reporter>
                        <labels>
                            <label>sharding</label>
                    </labels>
                <created>Fri, 5 Aug 2016 14:55:08 +0000</created>
                <updated>Mon, 30 Oct 2023 21:29:31 +0000</updated>
                            <resolved>Mon, 29 Aug 2016 17:05:49 +0000</resolved>
                                                    <fixVersion>Server_Docs_20231030</fixVersion>
                                    <component>manual</component>
                        <due></due>
                            <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1375210" author="ravind.kumar" created="Thu, 1 Sep 2016 22:40:54 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/docs/pull/2719&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/pull/2719&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1375102" author="xgen-internal-githook" created="Thu, 1 Sep 2016 21:16:56 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;username&apos;: u&apos;rkumar-mongo&apos;, u&apos;name&apos;: u&apos;ravind&apos;, u&apos;email&apos;: u&apos;ravind.kumar@10gen.com&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/DOCS-8512&quot; title=&quot;Primary Shard of new Database is Shard with least data on it&quot; class=&quot;issue-link&quot; data-issue-key=&quot;DOCS-8512&quot;&gt;&lt;del&gt;DOCS-8512&lt;/del&gt;&lt;/a&gt;: Primary Shard Selection Process&lt;/p&gt;

&lt;p&gt;Signed-off-by: kay &amp;lt;kay.kim@10gen.com&amp;gt;&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/docs/commit/ecb772a6a827ad24182e1b362a075f396a8ce5e3&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/commit/ecb772a6a827ad24182e1b362a075f396a8ce5e3&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1370811" author="ravind.kumar" created="Mon, 29 Aug 2016 17:05:49 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/docs/pull/2719&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/docs/pull/2719&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1348770" author="roy.rim" created="Fri, 5 Aug 2016 17:43:44 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=renctan&quot; class=&quot;user-hover&quot; rel=&quot;renctan&quot;&gt;renctan&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="1348716" author="renctan" created="Fri, 5 Aug 2016 17:16:01 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=roy.rim&quot; class=&quot;user-hover&quot; rel=&quot;roy.rim&quot;&gt;roy.rim&lt;/a&gt; No. !isOK in this context would be something like network error contacting the shard or invalid shard name or corrupted response format, etc. candidateSizeStatus will only contain the raw value for the data size in the shard if there are no errors and does not know about how full it is. Come to think of it, this code should probably also take into account the shardSize setting...&lt;/p&gt;</comment>
                            <comment id="1348706" author="roy.rim" created="Fri, 5 Aug 2016 17:09:11 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=renctan&quot; class=&quot;user-hover&quot; rel=&quot;renctan&quot;&gt;renctan&lt;/a&gt; not sure what candidateSizeStatus stands for but I assume it means that there is space available. So regardless of how much space is available on the other shards if the first one has no space you are not allowed to create a new database?&lt;/p&gt;

&lt;p&gt;If so I guess it makes sense since if any of your shards are full you probably have a problem.&lt;/p&gt;</comment>
                            <comment id="1348699" author="renctan" created="Fri, 5 Aug 2016 17:04:19 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=roy.rim&quot; class=&quot;user-hover&quot; rel=&quot;roy.rim&quot;&gt;roy.rim&lt;/a&gt; Yes. And that also applies to the other shards as well&lt;/p&gt;</comment>
                            <comment id="1348684" author="roy.rim" created="Fri, 5 Aug 2016 16:54:29 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=renctan&quot; class=&quot;user-hover&quot; rel=&quot;renctan&quot;&gt;renctan&lt;/a&gt; the first few lines in &lt;a href=&quot;https://github.com/mongodb/mongo/blob/r3.3.10/src/mongo/s/catalog/replset/sharding_catalog_client_impl.cpp#L286-L303&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/r3.3.10/src/mongo/s/catalog/replset/sharding_catalog_client_impl.cpp#L286-L303&lt;/a&gt;:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;auto candidateSizeStatus = shardutil::retrieveTotalShardSize(txn, candidateShardId);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    if (!candidateSizeStatus.isOK()) {&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;        return candidateSizeStatus.getStatus();&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;    }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;So if candidateSizeStatus is not OK for the first shard then this will error out? Just trying to understand.&lt;/p&gt;

&lt;p&gt;Roy&lt;/p&gt;</comment>
                            <comment id="1348569" author="renctan" created="Fri, 5 Aug 2016 15:34:55 +0000"  >&lt;p&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=ravind.kumar&quot; class=&quot;user-hover&quot; rel=&quot;ravind.kumar&quot;&gt;ravind.kumar&lt;/a&gt; Mongos selects the primary shard for a new database by picking the first shard that has the least amount of data. This logic has not changed since v1.6. The only change was how we determine the data size in the shard. Before v3.0, we were using mmapSize and with the introduction of WT, mmapSize doesn&apos;t make sense anymore, so we changed it to use the totalSize field from listDatabase command response instead.&lt;/p&gt;

&lt;p&gt;For reference:&lt;br/&gt;
v1.6: &lt;a href=&quot;https://github.com/mongodb/mongo/blob/v1.6/s/shard.cpp#L232-L238&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/v1.6/s/shard.cpp#L232-L238&lt;/a&gt;&lt;br/&gt;
v3.3: &lt;a href=&quot;https://github.com/mongodb/mongo/blob/r3.3.10/src/mongo/s/catalog/replset/sharding_catalog_client_impl.cpp#L286-L303&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo/blob/r3.3.10/src/mongo/s/catalog/replset/sharding_catalog_client_impl.cpp#L286-L303&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When is the primary shard chosen&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Every time mongos creates a new database entry in config.databases.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Is there a single primary shard, or is it per database&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;per database&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;How is the primary shard chosen&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;See above.&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                                        </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                <customfield id="customfield_10050" key="com.atlassian.jira.toolkit:comments">
                        <customfieldname># Replies</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_10055" key="com.atlassian.jira.ext.charting:firstresponsedate">
                        <customfieldname>Date of 1st Reply</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>Fri, 5 Aug 2016 15:21:13 +0000</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10052" key="com.atlassian.jira.toolkit:dayslastcommented">
                        <customfieldname>Days since reply</customfieldname>
                        <customfieldvalues>
                                        7 years, 23 weeks, 6 days 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_10040" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                        <customfieldname>Estimate</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10042"><![CDATA[Small]]></customfieldvalue>

                        </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>emet.ozar@mongodb.com</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_11151" key="com.atlassian.jira.toolkit:LastCommentDate">
                        <customfieldname>Last public comment date</customfieldname>
                        <customfieldvalues>
                            7 years, 23 weeks, 6 days ago
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                            <customfield id="customfield_10051" key="com.atlassian.jira.toolkit:participants">
                        <customfieldname>Participants</customfieldname>
                        <customfieldvalues>
                                        <customfieldvalue>xgen-internal-githook</customfieldvalue>
            <customfieldvalue>randolph@mongodb.com</customfieldvalue>
            <customfieldvalue>ravind.kumar</customfieldvalue>
            <customfieldvalue>roy.rim@mongodb.com</customfieldvalue>
    
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                        <customfield id="customfield_14254" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Product Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrmlhb:</customfieldvalue>

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

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="1222">Docs Q3 W3-4 (8/30)</customfieldvalue>
    <customfieldvalue id="1223">Docs Q3 W5 (9/6)</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                        <customfield id="customfield_10555" key="com.atlassian.jira.plugin.system.customfieldtypes:float">
                        <customfieldname>Story Points</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1.0</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <customfield id="customfield_10053" key="com.atlassian.jira.ext.charting:timeinstatus">
                        <customfieldname>Time In Status</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            <customfield id="customfield_14350" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>serverRank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>1|hrzanz:</customfieldvalue>

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