1
votes

I have question about use mongos with Shard,I build shard cluster in our dev environment I had two shards(NOT include replset just for test) one config and one mongos when I shutdown a shard the mongos can't find data(such as find(),count()...).it throw a socket exception like this: socket exception [CONNECT_ERROR] for 127.0.0.1:20000 code:11002 can anyone help me to figure out where is the problem,i saw the docs before it wrote about in the sharding cluster if a shard crashed the mongos can still work. i appreciate your help,thx i use these shell to build it

shard 1
mongod --shardsvr  --port 10000 --dbpath c:\shard\data\shard1\r0 --oplogSize         64 --logpath c:\shard\logs\r0.log --logappend  

shard2
mongod --shardsvr  --port 20000 --dbpath     c:\shard\data\shard2\r0 --oplogSize 64 --logpath c:\shard\logs\r3.log --logappend  

config
mongod --configsvr --dbpath c:\shard\data\config --port 40000 --logpath     c:\shard\logs\config.log --logappend  

mongos
mongos --configdb 127.0.0.1:40000 --port 50000 --chunkSize 1 --logpath     c:\shard\logs\mongos.log --logappend 


mongo 127.0.0.1:50000/admin  
db.runCommand({addshard:"127.0.0.1:10000",name:"ShardSetA"})  
db.runCommand({addshard:"127.0.0.1:20000",name:"ShardSetB"})  
db.runCommand({enablesharding:"Staff"});  
var server=["127.0.0.1:10000","127.0.0.1:20000"]
db.runCommand({shardcollection:"Staff.StaffInfo",key:{StaffName:1}})  

for ( var x=65; x<=65+25; x+=10 ){
var index=x+10>65+25?65+25:x+10;
 db.runCommand( { split : "Staff.StaffInfo" , middle : { StaffName:      String.fromCharCode(index)} } );} 

var i=0;
for ( var x=65; x<=97+25; x+=10 ){db.adminCommand( {moveChunk :    "Staff.StaffInfo" ,find : {StaffName: x},  to : server[i%2] });i++} 
1

1 Answers

0
votes

I had solved this problem there are three situations for the problem 1. query from normal shard ,mongodb can provide right data 2.query from all the shards(include offline shard) mongodb will throw exception 3.query from offline shard mongodb wiil throw exception

so if you want to keep high-performance sharding please use replset! if you query from other dirvers please set partial flag to provide return data from normal shard