【问题标题】:Way for resolving "Temporary file write failure" in case of select statement在select语句的情况下解决“临时文件写入失败”的方法
【发布时间】:2020-12-01 05:28:20
【问题描述】:

我们正面临一个奇怪的问题。在我们的一项服务中(应用程序中大约有 12 到 13 个服务),同时执行 SQL 查询(select 语句),该查询返回大约 30 40 行,执行时间不到一秒。

我们间歇性地收到“临时文件写入失败”异常

下面是一段代码

 Query qry = null;

  //selectquery is of type String whose value is read from properties file using @Value("${})
  qry = entityManager.createNativeQuery(selectquery);
              //set few parameters here   
             
            
 List result = qry.getResultList();
           
           

我们遇到了异常

<Log_Created_Date: 2020/08/11 17:59:21> <Log_Level: ERROR> <application_name: abc> <Class_Name: com.pqr> <Method_Name: someMethod> <Exception: java.sql.SQLException: Temporary file write failure.

完整的错误日志如下

<Log_Created_Date: 2020/08/11 17:59:21> <Log_Level: ERROR> <application_name: abc> <Class_Name: com.pqr> <Method_Name: someMethod> <Exception: java.sql.SQLException: Temporary file write failure.
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
        at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003)
        at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
        at org.apache.tomcat.dbcp.dbcp2.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:82)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
        ... 158 common frames omitted
Wrapped by: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:2167)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1930)
        at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1892)
        at org.hibernate.loader.Loader.doQuery(Loader.java:937)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
        at org.hibernate.loader.Loader.doList(Loader.java:2689)
        at org.hibernate.loader.Loader.doList(Loader.java:2672)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
        at org.hibernate.loader.Loader.list(Loader.java:2501)
        at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:338)
        at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2223)
        at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1053)
        at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:168)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1506)
        ... 144 common frames omitted
Wrapped by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not extract ResultSet
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)
        at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1515)
        at org.hibernate.query.Query.getResultList(Query.java:146)
        at com.pqr.someMethod(pqr.java:259)

在所有服务中,此异常仅出现在其中一项服务中。我们正在从所有服务连接到同一个数据库。 其他服务与此服务的区别在于它的使用频率更高。

我们没有改变任何东西,也没有试图创造任何东西。就是简单的select语句。

我们检查了临时空间(数据库服务器上的 /tmp 目录),每次发生此异常时都有大量可用空间。

感谢任何帮助。谢谢!

【问题讨论】:

  • 我仍然认为是磁盘空间问题。你能从你的 mysql 配置 my.cnf 中仔细检查哪个目录被用作“tempdir”吗?
  • @cool /Mysql/tmp 作为 tempdir 用户

标签: java mysql hibernate microservices


【解决方案1】:

这恰好是数据库/服务器相关问题。

在部署/运行数据库的服务器上增加 ulimit 参数的值解决了这个问题。

MySQL 使用临时表来解决复杂的查询。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    • 2019-03-06
    • 2012-06-22
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多