Reputation: 627
I am using CloudSolrClient with Spring boot Solr 1.5.18.RELEASE and Solr Version is Solr 4.10.3.
SolrClient solrClient= new CloudSolrClient.Builder().withZkHost(zkHosts).withZkChroot(solrProperties.getSolrZookeeperLocation()).build();
When I use Solr which comes wth CDH 5.16.1 default i.e. Solr 4.10.3 while saving document I get following error :
org.springframework.data.solr.UncategorizedSolrException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map; nested exception is org.apache.solr.client.solrj.SolrServerException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:168)
at org.springframework.data.solr.core.SolrTemplate.saveBeans(SolrTemplate.java:223)
at com.solix.emailarchiving.email.solr.search.SolrTemplateWrapper.saveBeans(SolrTemplateWrapper.java:33)
at com.solix.emailarchiving.email.solr.search.EmailSearchRepositoryImpl.saveEmails(EmailSearchRepositoryImpl.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy153.saveEmails(Unknown Source)
at com.solix.emailarchiving.email.EmailSolrServiceImpl.saveEmails(EmailSolrServiceImpl.java:24)
at com.solix.emailarchiving.email.EmailSolrServiceImpl$$FastClassBySpringCGLIB$$40f18538.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
at com.solix.emailarchiving.annotation.ServiceTransactionAspect.beforeMethod(ServiceTransactionAspect.java:46)
at sun.reflect.GeneratedMethodAccessor138.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:643)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:632)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.solix.emailarchiving.email.EmailSolrServiceImpl$$EnhancerBySpringCGLIB$$a84565b1.saveEmails(<generated>)
at com.solix.emailarchiving.hbasetosolrsync.EmailsSync.sendEmailsToSolr(EmailsSync.java:157)
at com.solix.emailarchiving.hbasetosolrsync.EmailsSync.syncMailsFromHbaseToSolr(EmailsSync.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:750)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689)
at com.solix.emailarchiving.hbasetosolrsync.EmailsSync$$EnhancerBySpringCGLIB$$2714482.syncMailsFromHbaseToSolr(<generated>)
at com.solix.emailarchiving.hbasetosolrsync.HBaseToSolrEmailSyncConsumer.processEmailIdModels(HBaseToSolrEmailSyncConsumer.java:129)
at com.solix.emailarchiving.hbasetosolrsync.HBaseToSolrEmailSyncConsumer.hbaseToSolrSyncListen(HBaseToSolrEmailSyncConsumer.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)
at org.springframework.kafka.listener.adapter.HandlerAdapter.invoke(HandlerAdapter.java:48)
at org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.invokeHandler(MessagingMessageListenerAdapter.java:248)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:80)
at org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter.onMessage(RecordMessagingMessageListenerAdapter.java:51)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1001)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:981)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:932)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:801)
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:689)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.solr.client.solrj.SolrServerException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:1246)
at org.apache.solr.client.solrj.impl.CloudSolrClient.request(CloudSolrClient.java:1073)
at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160)
at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:106)
at org.springframework.data.solr.core.SolrTemplate.lambda$saveBeans$3(SolrTemplate.java:223)
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:164)
... 66 more
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.apache.solr.common.cloud.DocRouter.getRouteField(DocRouter.java:53)
at org.apache.solr.common.cloud.CompositeIdRouter.sliceHash(CompositeIdRouter.java:46)
at org.apache.solr.common.cloud.HashBasedRouter.getTargetSlice(HashBasedRouter.java:38)
at org.apache.solr.client.solrj.request.UpdateRequest.getRoutes(UpdateRequest.java:262)
at org.apache.solr.client.solrj.impl.CloudSolrClient.directUpdate(CloudSolrClient.java:771)
at org.apache.solr.client.solrj.impl.CloudSolrClient.sendRequest(CloudSolrClient.java:1263)
at org.apache.solr.client.solrj.impl.CloudSolrClient.requestWithRetryOnStaleState(CloudSolrClient.java:1134)
... 71 more
After when I dug little deeper and googling I came to know that issue is something related to router field in zookeepers clusterstate.json
Info about my collection in clusterstate.json is
"88_Exchange12_2":{
"shards":{"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{"core_node1":{
"state":"active",
"core":"88_Exchange12_2_shard1_replica1",
"node_name":"SEZ-DESK-047-Linux:8983_solr",
"base_url":"http://SEZ-DESK-047-Linux:8983/solr",
"leader":"true"}}}},
"maxShardsPerNode":"1",
"router":"compositeId",
"replicationFactor":"1",
"autoAddReplicas":"false",
"routerSpec":{"name":"compositeId"}},
Value in router field is expected to be like "router":{"name":"compositeId"}. hoewever it is getting stored incorrect and thus result into above ClassCastException.
However when I use Apache Solr same version 4.10.3 (not CDH Solr 4.10.3 ), "router" set with correct value.
"92_S2R1_35":{
"replicationFactor":"1",
"shards":{
"shard1":{
"range":"80000000-ffffffff",
"state":"active",
"replicas":{"core_node2":{
"core":"92_S2R1_35_shard1_replica1",
"base_url":"http://172.52.110.44:8983/solr",
"node_name":"172.52.110.44:8983_solr",
"state":"down",
"leader":"true"}}},
"shard2":{
"range":"0-7fffffff",
"state":"active",
"replicas":{}}},
"router":{"name":"compositeId"},
"maxShardsPerNode":"1",
"autoAddReplicas":"false",
"autoCreated":"true"}
Q1. How to solve this. Can we set router programatically from java code while creating Collection? Below is how I create collection:
SolrZkClient solrZkClient=null;
try {
String solrZkUrl= solrProperties.getSolrZookeerHost()+solrProperties.getSolrZookeeperLocation();
solrZkClient = new SolrZkClient(solrZkUrl, 10000);
Resource resource = new ClassPathResource(solrConfig);
java.nio.file.Path path = Paths.get(resource.getURI());
solrZkClient.upConfig(path, solrConfigName);
LOG.info("Solr Config created with name : \"" + solrConfigName+ "\"");
}catch (IOException e) {
LOG.error("Something went Wrong while creating SolrConfig for tenantId: "+ tenantId , e);
}finally {
if (solrZkClient != null) {
solrZkClient.close();
}
}
int numShards=(solrProperties.getNumShards()<=0)?1:solrProperties.getNumShards();
int numReplicas=(solrProperties.getNumReplicas()<=0)?1:solrProperties.getNumReplicas();
SolrClient solrClient=null;
try {
Create collection = CollectionAdminRequest.createCollection(collectiomName, solrConfigName, numShards, numReplicas);
// collection.setMaxShardsPerNode(-1);
solrClient = solrConectionUtils.solrClient(tenantId);
CollectionAdminResponse response = collection.process(solrClient);
if (!response.isSuccess()) {
LOG.error(response.getErrorMessages().toString());
throw new ApplicationException(ExceptionCodeType.SOLR_COLLECTION_CREATION_FAILED);
} else {
LOG.info("Collection created with name : \"" + collection.getCollectionName()+ "\"");
}
} catch (SolrException | SolrServerException e) {
LOG.error("Something went wrong while creating collection");
}finally {
if (solrClient != null) {
solrClient.close();
}
}
Q2. In CDH's clusterstate.json we can see one more field named 'routerSpec' which has correct value, but i think its not getting used. Is there a way to use this field as router and get the work done?
Upvotes: 0
Views: 1240
Reputation: 210
The router attribute was indeed changed from a string to a map in Solr 4.5.0 but there was back-compatible read code added to the solrj client to avoid this situation. I do not know why you are seeing this error in 4.10.3, the getRouterField method in 4.10.3 is https://github.com/apache/lucene-solr/blob/d52936c3c3f92aa3d04eaeeab3472a6e259be7b6/solr/solrj/src/java/org/apache/solr/common/cloud/DocRouter.java#L52 which checks if the router object is a string and returns null. If nothing else, perhaps you can manually modify the cluster state object in zookeeper to change the router to a json map.
Upvotes: 1