[SERVER-9931] hashed shard keys do not appear to handle decimal values Created: 13/Jun/13  Updated: 10/Dec/14  Resolved: 27/Aug/14

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.4.2
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Edouard Servan-Schreiber Assignee: Greg Studer
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-14759 Splitting very close to an existing d... Closed
is related to SERVER-14761 split command should only allow Numbe... Closed
Operating System: ALL
Steps To Reproduce:

// Set up a sharding test.
var st = new ShardingTest({ shards : 4, mongos: 1, chunksize : 64, config : 1, other : { nopreallocj : 1 }});
st.adminCommand(

{ enablesharding:"test" }

);
st.adminCommand( { shardcollection:"test.hashed", key:

{ _id: 'hashed' }

} );

function insertData(db, colName, num, w) {
    start=db.serverStatus().uptimeMillis;
    col = db.getCollection(colName);
col.remove();
    for (i = 0; i < num; i++) {
        col.insert({_id: Math.random()});
        db.getLastErrorObj(w); // call gle safe
    }
    end=db.serverStatus().uptimeMillis;
    return ((num*1000)/(end-start));
}

//
num = 50000;
hashed=insertData(db.getSiblingDB( "test" ), 'hashed', num,1);

Participants:

 Description   

Tried using a hashed shard key after defining an empty collection as hashed sharded. All decimal values between 0 and 1 were routed to the same shard.



 Comments   
Comment by Greg Studer [ 27/Aug/14 ]

We don't recommend using floating-point values as shard keys - arithmetic can cause surprising results. The current behavior is built into the hashed indexes and is not currently changeable - though a simple workaround is to transform the double value into another type if small decimal increments really are being used as unique _ids.

Comment by Spencer Brody (Inactive) [ 13/Jun/13 ]

This is a known issue, see the warning on this page: http://docs.mongodb.org/manual/tutorial/shard-collection-with-a-hashed-shard-key/

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