if (index > 100000000) {
index = 0l;
InsertIndex.set(index);
}
JSONObject rtn = new JSONObject();
if(tp==null||tp.equals(FlushType.buffer))
{
ShardsList write =null;
if(islocal)
{
ArrayList<ShardsList> list=new ArrayList<GetShards.ShardsList>(cores.length);
for(ShardsList shard:cores)
{
if(shard.containsIp(localip))
{
list.add(shard);
}
}
if(list.size()>0)
{
write =list.get((int) (index %list.size()));
}
}
if(write==null)
{
write = cores[(int) (index % cores.length)];
}
for (String s : write.list) {
String url = "http://" + s + "/solr/" + projectName;
try{
CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
server.setConnectionManagerTimeout(60000l);
server.setSoTimeout(60000);
server.setConnectionTimeout(10000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false);
server.setAllowCompression(false);
server.setMaxRetries(4);
server.setRequestWriter(new BinaryRequestWriter());
UpdateRequest req = new UpdateRequest();
req.add(docs);
UpdateResponse rsp = req.process(server);
rtn.put(s, rsp.toString());
}catch(Throwable e)
{
LOG.error("insert error "+url,e);
throw new Exception(e);
}
}
}else if(tp.equals(FlushType.sync)||tp.equals(FlushType.syncHdfs))
{
for(ShardsList write:cores)
{
for (String s : write.list) {
String url = "http://" + s + "/solr/" + projectName;
try{
CommonsHttpSolrServer server = new CommonsHttpSolrServer(url);
server.setConnectionManagerTimeout(60000l);
server.setSoTimeout(60000);
server.setConnectionTimeout(10000);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false);
server.setAllowCompression(false);
server.setMaxRetries(4);
server.setRequestWriter(new BinaryRequestWriter());
UpdateRequest req = new UpdateRequest();
req.add(docs);
UpdateResponse rsp = req.process(server);
rtn.put(s, rsp.toString());
}catch(Throwable e)
{
LOG.error("insert error "+url,e);
throw new Exception(e); }
}
}
}
rtn.put("code","1");
rtn.put("message","success");
return rtn.toString();
}