In case jOOQ can't connect to a database, executing SQL against it will result in a DataAccessException.
Is there a way to get the url of the database/connection against which the query was attempted, just from this error?
Edit, adding more context:
We have a simple connection pooling implementation using a HashMap and its computeIfAbsent().
If DSL.using(url) does not throw an Exception, we consider the connection established and keep the resulting DSLContext as value in said map (url is key).
Assume there are multiple connections in the pool.
We have an ExecuteListener attached to the DSLContext and in it, we catch DataAccessExceptions. When caught, we validate the connection with: executeContext.dsl().diagnosticsConnection().isValid(1).
If the connection became invalid, we would like to flag it as such but the only way to find out which one it is, is to loop over the connection pool map because executeContext.dsl().parsingConnection().getMetaData().getURL() is no longer an option.
Here's an example stack trace. It's different for each of the DB engines we connect to but always wrapped in org.jooq.exception.DataAccessException.
org.jooq.exception.DataAccessException: SQL [select count(*) from (select * from actor) as `alias_4914265`]; (conn=1) unexpected end of stream, read 0 bytes from 4 (socket was closed by server)
at org.jooq_3.12.3.MARIADB.debug(Unknown Source)
at org.jooq.impl.Tools.translate(Tools.java:2717)
at org.jooq.impl.DefaultExecuteContext.sqlException(DefaultExecuteContext.java:755)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:382)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:501)
at org.jooq.impl.AbstractResultQuery.fetchLazy(AbstractResultQuery.java:470)
at org.jooq.impl.AbstractResultQuery.fetchLazyNonAutoClosing(AbstractResultQuery.java:484)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:653)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:605)
at org.jooq.impl.AbstractResultQuery.fetchOne(AbstractResultQuery.java:611)
at org.jooq.impl.SelectImpl.fetchOne(SelectImpl.java:2847)
at com.datoris.base.AbstractBaseTypeImpl.executeReport(AbstractBaseTypeImpl.java:134)
at com.datoris.service.ReportService.executeReport(ReportService.java:508)
at com.datoris.verticle.ReportVerticle.lambda$completeStartup$0(ReportVerticle.java:29)
at io.vertx.core.eventbus.impl.HandlerRegistration.deliver(HandlerRegistration.java:261)
at io.vertx.core.eventbus.impl.HandlerRegistration.handle(HandlerRegistration.java:239)
at io.vertx.core.eventbus.impl.EventBusImpl$InboundDeliveryContext.next(EventBusImpl.java:565)
at io.vertx.core.eventbus.impl.EventBusImpl.lambda$deliverToHandler$5(EventBusImpl.java:524)
at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:320)
at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:34)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLNonTransientConnectionException: (conn=1) unexpected end of stream, read 0 bytes from 4 (socket was closed by server)
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.get(ExceptionMapper.java:240)
at org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper.getException(ExceptionMapper.java:171)
at org.mariadb.jdbc.MariaDbStatement.executeExceptionEpilogue(MariaDbStatement.java:248)
at org.mariadb.jdbc.ClientSidePreparedStatement.executeInternal(ClientSidePreparedStatement.java:230)
at org.mariadb.jdbc.ClientSidePreparedStatement.execute(ClientSidePreparedStatement.java:157)
at org.jooq.tools.jdbc.DefaultPreparedStatement.execute(DefaultPreparedStatement.java:209)
at org.jooq.impl.Tools.executeStatementAndGetFirstResultSet(Tools.java:3928)
at org.jooq.impl.AbstractResultQuery.execute(AbstractResultQuery.java:294)
at org.jooq.impl.AbstractQuery.execute(AbstractQuery.java:368)
... 20 common frames omitted
Caused by: java.sql.SQLNonTransientConnectionException: unexpected end of stream, read 0 bytes from 4 (socket was closed by server)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.handleIoException(AbstractQueryProtocol.java:1925)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1437)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:1415)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:289)
at org.mariadb.jdbc.ClientSidePreparedStatement.executeInternal(ClientSidePreparedStatement.java:221)
... 25 common frames omitted
Caused by: java.io.EOFException: unexpected end of stream, read 0 bytes from 4 (socket was closed by server)
at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacketArray(StandardPacketInputStream.java:246)
at org.mariadb.jdbc.internal.io.input.StandardPacketInputStream.getPacket(StandardPacketInputStream.java:215)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.readPacket(AbstractQueryProtocol.java:1435)
... 28 common frames omitted
Related
how can I avoid WARN messages to be displayed in logs (without putting the log4j level to ERROR) when I launch Confluent ?
I have set up my plugin.path variable in the properties file with value ${CONFLUENT_HOME}/share/java/kafka-connect-jdbc (with final comma).
I tried to put in the classpath the kafka-connect-jdbc repository, without success.
The following is just an example a small part of the log file:
[2018-07-10 15:40:30,168] INFO Reflections took 1 ms to scan 1 urls, producing 5 keys and 6 values [using 1 cores] (org.reflection
s.Reflections)
[2018-07-10 15:40:30,170] WARN could not get type for name org.jmock.Mockery from any class loader (org.reflections.Reflections)
org.reflections.ReflectionsException: could not get type for name org.jmock.Mockery
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:390)
at org.reflections.Reflections.expandSuperTypes(Reflections.java:381)
at org.reflections.Reflections.<init>(Reflections.java:126)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader$InternalReflections.<init>(DelegatingClassLoader.java:
365)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader.scanPluginPath(DelegatingClassLoader.java:277)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader.scanUrlsAndAddPlugins(DelegatingClassLoader.java:216)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader.registerPlugin(DelegatingClassLoader.java:208)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader.initPluginLoader(DelegatingClassLoader.java:177)
at org.apache.kafka.connect.runtime.isolation.DelegatingClassLoader.initLoaders(DelegatingClassLoader.java:154)
at org.apache.kafka.connect.runtime.isolation.Plugins.<init>(Plugins.java:56)
at org.apache.kafka.connect.cli.ConnectStandalone.main(ConnectStandalone.java:77)
Caused by: java.lang.ClassNotFoundException: org.jmock.Mockery
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.reflections.ReflectionUtils.forName(ReflectionUtils.java:388)
... 10 more
That does not seem causing any issues, but can be confusing to read about it.
Have you got any suggestions about that ?
Thanks in advance,
Diego
You can set log level for particular package in log4j config file:
log4j.logger.org.reflections=ERROR
This helped me
I am writing tests which run OkHttp/Retrofit requests against a MockWebServer. Among other things I'm testing timeouts. Here I noticed, that some of my timeout tests do not produce the same kind of exception all the time:
While the exception thrown is always a SocketTimeoutException, the exception message differs between two possibilities. Sometimes I get
"timeout", sometimes
"Read timed out".
There seems to be no clear pattern (it's the very same test which sometimes produces one or the other of these exception messages).
I assume that different constellations/causes lead to the differing messages... Can somebody explain to me the difference between these two cases?
Here are the corresponding stack traces:
"Read timed out"
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at okio.Okio$2.read(Okio.java:140)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:238)
at okio.RealBufferedSource.read(RealBufferedSource.java:45)
at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381)
at okio.RealBufferedSource.read(RealBufferedSource.java:45)
at okio.ForwardingSource.read(ForwardingSource.java:35)
at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:279)
at okio.RealBufferedSource$1.read(RealBufferedSource.java:386)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1016)
at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787)
at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:739)
at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:714)
at com.google.gson.internal.bind.TypeAdapters$35$1.read(TypeAdapters.java:910)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)
"timeout"
Caused by: java.net.SocketTimeoutException: timeout
at okio.Okio$3.newTimeoutException(Okio.java:212)
at okio.AsyncTimeout.exit(AsyncTimeout.java:288)
at okio.AsyncTimeout$2.read(AsyncTimeout.java:242)
at okio.RealBufferedSource.read(RealBufferedSource.java:45)
at okhttp3.internal.http.Http1xStream$FixedLengthSource.read(Http1xStream.java:381)
at okio.RealBufferedSource.read(RealBufferedSource.java:45)
at okio.ForwardingSource.read(ForwardingSource.java:35)
at retrofit2.OkHttpCall$ExceptionCatchingRequestBody$1.read(OkHttpCall.java:279)
at okio.RealBufferedSource$1.read(RealBufferedSource.java:386)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1287)
at com.google.gson.stream.JsonReader.nextQuotedValue(JsonReader.java:1016)
at com.google.gson.stream.JsonReader.nextName(JsonReader.java:787)
at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:739)
at com.google.gson.internal.bind.TypeAdapters$29.read(TypeAdapters.java:714)
at com.google.gson.internal.bind.TypeAdapters$35$1.read(TypeAdapters.java:910)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:37)
at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:25)
at retrofit2.ServiceMethod.toResponse(ServiceMethod.java:117)
at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:211)
at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:106)
I'm trying to run a query to my local solr server (single instance).
I'm also adding filters for ids.
So in case of 10000 ids I create 10 Filter Queries, each of which consists of 1000 ids.
Filter Query looks like this:
"id:(1 2 3 n)"
I'm also using Solrj so it goes like:
query.addFilterQuery("id:(1 2 3 n)");
But after some threshold (it was 1000 5 minutes ago and now it's around 800) I'm starting to receive exceptions:
org.apache.solr.client.solrj.SolrServerException: No live SolrServers available to handle this request
Caused by: org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://localhost:8080/solr
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:416)
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181)
at org.apache.solr.client.solrj.impl.LBHttpSolrServer.request(LBHttpSolrServer.java:447)
... 37 more
Caused by: java.net.SocketException: Software caused connection abort: recv failed
I googled around but found only about maxBoolean queries which is not my case probably
Yes Igor,
You are correct.
By default Solrj uses GET instead of POST.
So you have to use server.query(query, SolrRequest.METHOD.POST).
Do you know where can I set auto-import="false" when working with hyperjaxb?. I have this exception when calling Persistence.createEntityManagerFactory().
Assuming that this auto-import solves my problem, I would assume that I have to do manual importing instead. Where would I go about looking for such information?
Thank you.
Exception in thread "main" javax.persistence.PersistenceException: [PersistenceUnit: com.sun.java.xml.ns.persistence:org.jvnet.hyperjaxb3.ejb.schemas.customizations:com.sun.java.xml.ns.persistence.orm:generated] Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:125)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:52)
at PropertiesTest.Test1(PropertiesTest.java:68)
at PropertiesTest.main(PropertiesTest.java:121)
Caused by: org.hibernate.AnnotationException: Use of the same entity name twice: Basic
at org.hibernate.cfg.annotations.EntityBinder.bindEntity(EntityBinder.java:304)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:567)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:191)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:253)
... 4 more
Caused by: org.hibernate.DuplicateMappingException: duplicate import: Basic refers to both org.jvnet.hyperjaxb3.ejb.schemas.customizations.Basic and com.sun.java.xml.ns.persistence.orm.Basic (try using auto-import="false")
at org.hibernate.cfg.Mappings.addImport(Mappings.java:164)
at org.hibernate.cfg.annotations.EntityBinder.bindEntity(EntityBinder.java:297)
... 13 more
I am using grails with mysql 5. I am using .withTransaction for transaction management in a service. Within the withTransaction block I am using savePoint() method which is causing the following exception. Note: I am using setRollbackOnly() method without any issue.
2011-06-26 23:02:37,818 [quartzScheduler_Worker-7] ERROR listeners.ExceptionPrinterJobListener - Exception occured in job: GRAILS_JOBS.com.exmp.bdg.PowerRollupJob
org.quartz.JobExecutionException: Transaction manager does not allow nested transactions [See nested exception: org.springframework.transaction.NestedTransactionNotSupportedException: Transaction manager does not allow nested transactions]
at org.codehaus.groovy.grails.plugins.quartz.GrailsJobFactory$GrailsTaskClassJob.execute(GrailsJobFactory.java:81)
at org.quartz.core.JobRunShell.run(JobRunShell.java:199)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546)
Caused by: org.springframework.transaction.NestedTransactionNotSupportedException: Transaction manager does not allow nested transactions
at org.springframework.jdbc.datasource.JdbcTransactionObjectSupport.getConnectionHolderForSavepoint(JdbcTransactionObjectSupport.java:151)
at org.springframework.jdbc.datasource.JdbcTransactionObjectSupport.createSavepoint(JdbcTransactionObjectSupport.java:104)
at org.springframework.transaction.support.AbstractTransactionStatus.createSavepoint(AbstractTransactionStatus.java:176)
at org.springframework.transaction.SavepointManager$createSavepoint.call(Unknown Source)
at com.exmp.bdg.service.PowerRollupService$_doRollup_closure2.doCall(PowerRollupService.groovy:85)
By default the transaction manager for hibernate and MySQL don't have the save points enabled.
In BootStrap.groovy add the following:
transactionManager.setNestedTransactionAllowed(true)
Then in a transaction you can do the following:
Thing.withTransaction { status ->
//Do some work and a save
def savePoint = status.createSavepoint()
//do other work
if(checkOk)
{
//Everything worked so don't need the save point anymore
status.releaseSavepoint(savePoint)
}
else
{
//The other work did not work so rollback from it.
status.rollbackToSavepoint(savePoint)
}
}