Skip to content

Instantly share code, notes, and snippets.

@ObjectIsAdvantag
Last active December 2, 2015 21:23
Show Gist options
  • Save ObjectIsAdvantag/3609a93f2b51ac6d882e to your computer and use it in GitHub Desktop.
Save ObjectIsAdvantag/3609a93f2b51ac6d882e to your computer and use it in GitHub Desktop.
M202 - week 5
> mongo --nodb
> config = { shard0 : { smallfiles : "", noprealloc : "", nopreallocj : ""}, shard1 : { smallfiles : "", noprealloc : "", nopreallocj : "" }, shard2 : { smallfiles : "", noprealloc : "", nopreallocj : ""}};
{
"shard0" : {
"smallfiles" : "",
"noprealloc" : "",
"nopreallocj" : ""
},
"shard1" : {
"smallfiles" : "",
"noprealloc" : "",
"nopreallocj" : ""
},
"shard2" : {
"smallfiles" : "",
"noprealloc" : "",
"nopreallocj" : ""
}
> cluster = new ShardingTest( { shards : config , other : {manualAddShard:true}} );
.... processes start
... ps -aux command results
Then, start a new mongo shell
> mongo --port 30999
mongos> db.adminCommand({ addShard: "localhost:30000", name: "shard0" });
mongos> db.adminCommand({ addShard: "localhost:30001", name: "shard1" });
mongos> db.adminCommand({ addShard: "localhost:30002", name: "shard2" });
mongos> sh.enableSharding("m202")
mongos> sh.status(true)
mongos> sh.stopBalancer()
mongos> db.adminCommand({split : "m202.presplit", middle : { a : 0 }})
... add other splits (chunks)
mongos> sh.status(true)
m202@m202-ubuntu1404:~$ mongo --port 30999
MongoDB shell version: 2.6.4
connecting to: 127.0.0.1:30999/test
mongos> sh.status()
--- Sharding Status ---
sharding version: {
"_id" : 1,
"version" : 4,
"minCompatibleVersion" : 4,
"currentVersion" : 5,
"clusterId" : ObjectId("5535858fdf17a2b7969aa268")
}
shards:
{ "_id" : "shard0", "host" : "localhost:30000" }
{ "_id" : "shard1", "host" : "localhost:30001" }
{ "_id" : "shard2", "host" : "localhost:30002" }
databases:
{ "_id" : "admin", "partitioned" : false, "primary" : "config" }
{ "_id" : "test", "partitioned" : false, "primary" : "shard1" }
{ "_id" : "m202", "partitioned" : true, "primary" : "shard1" }
m202.presplit
shard key: { "a" : 1 }
chunks:
shard1 4
shard0 3
shard2 4
{ "a" : { "$minKey" : 1 } } -->> { "a" : 0 } on : shard1 Timestamp(9, 1)
{ "a" : 0 } -->> { "a" : 7 } on : shard0 Timestamp(11, 1)
{ "a" : 7 } -->> { "a" : 10 } on : shard0 Timestamp(3, 0)
{ "a" : 10 } -->> { "a" : 14 } on : shard0 Timestamp(10, 0)
{ "a" : 14 } -->> { "a" : 15 } on : shard1 Timestamp(11, 0)
{ "a" : 15 } -->> { "a" : 20 } on : shard1 Timestamp(1, 11)
{ "a" : 20 } -->> { "a" : 21 } on : shard1 Timestamp(1, 13)
{ "a" : 21 } -->> { "a" : 22 } on : shard2 Timestamp(10, 1)
{ "a" : 22 } -->> { "a" : 23 } on : shard2 Timestamp(6, 0)
{ "a" : 23 } -->> { "a" : 24 } on : shard2 Timestamp(7, 0)
{ "a" : 24 } -->> { "a" : { "$maxKey" : 1 } } on : shard2 Timestamp(8, 0)
... move chunks if necessary
mongos> sh.moveChunk("m202.presplit", {"a": 14}, "shard1")
... done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment