【问题标题】:Raven DB 4.1.2 hangs on streaming query in JavaRaven DB 4.1.2 在 Java 中挂起流式查询
【发布时间】:2018-11-21 17:56:16
【问题描述】:

我有一个基于 jax-rs 的 REST 服务,我使用 Java 11 在 64 位 Linux 上的 Tomcat 8.5 上运行;此服务连接到同一 Linux 机器上的 RavenDB 4.1.2 实例。我利用流式查询返回请求结果。我使用 Postman 提交相同的请求,一切正常:返回结果,而且速度相当快。

但是 - 它只能工作 10 次。当我第 11 次提交与之前相同的请求时,results = currentSession.advanced().stream(query); 行挂起并且不会返回。 起初我以为我可能与StreamingOutputOutputStreamWriter 没有正确关闭有关。或者可能与Response 有关 - 但是当我在调试模式下逐步浏览 Eclipse 中部署的代码时,我注意到执行挂在该流线上。 (我发现正好 10 次是一个特殊的“人类选择”类型的数字......)

我的代码的相关部分:

@GET
@Path("/abcntr/{ccode}/{st}/{zm}") 
@Produces(MediaType.TEXT_PLAIN)
@Consumes(MediaType.TEXT_PLAIN)
public Response retrieveInfo(@PathParam("ccode") String ccode, @PathParam("st") String st, @PathParam("zm") String zm)
{
    (...)
    StreamingOutput adminAreaStream = new StreamingOutput()
    {
        ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();

        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException
        {
            try(IDocumentSession currentSession = ServiceListener.ravenDBStore.openSession())
            {
                Writer writer = new BufferedWriter(new OutputStreamWriter(output));
                (...)
                if(indexToBeQueried.startsWith("Level0"))
                {                                         
                    IDocumentQuery<AdministrativeArea> query = currentSession.query(area.class, Query.index(indexToBeQueried))
                            .whereEquals("i", ccode);
                    results = currentSession.advanced().stream(query); 
                }
                else 
                {
                    IDocumentQuery<AdministrativeArea> query = currentSession.query(area.class, Query.index(indexToBeQueried))
                            .whereEquals("i", ccode)
                            .andAlso()
                            .whereEquals("N1", sName);
                    results = currentSession.advanced().stream(query);  // THIS IS WHERE IT DOESNT COME BACK
                }
                while(results.hasNext())
                {
                    StreamResult<AdministrativeArea> adma = results.next();  
                    adma.getDocument().properties = retrievePropertiesForArea(adma.getDocument(), currentSession);
                    writer.write(ow.writeValueAsString(adma.getDocument()));
                    writer.write(",");
                }

                (...)
                currentSession.advanced().clear();
                currentSession.close();
            }
            catch (Exception e)
            {
                System.out.println("Exception: " + e.getMessage() + e.getStackTrace());
            }
        }
    };

    if(!requestIsValid)
        return Response.status(400).build();
    else
        return Response.ok(adminAreaStream).build();
}

RavenDB 错误日志是空的,Tomcat 错误日志也是如此。唯一类似于与此相关的错误消息的是“收集调试信息”中显示的内容:

System.ArgumentNullException: Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at Raven.Server.Documents.Handlers.Debugging.QueriesDebugHandler.QueriesCacheList() in C:\Builds\RavenDB-Stable-4.1\src\Raven.Server\Documents\Handlers\Debugging\QueriesDebugHandler.cs:line 181
   at Raven.Server.ServerWide.LocalEndpointClient.InvokeAsync(RouteInformation route, Dictionary`2 parameters) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Server\ServerWide\LocalEndpointClient.cs:line 61
   at Raven.Server.ServerWide.LocalEndpointClient.InvokeAndReadObjectAsync(RouteInformation route, JsonOperationContext context, Dictionary`2 parameters) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Server\ServerWide\LocalEndpointClient.cs:line 91
   at Raven.Server.Documents.Handlers.Debugging.ServerWideDebugInfoPackageHandler.WriteForDatabase(ZipArchive archive, JsonOperationContext jsonOperationContext, LocalEndpointClient localEndpointClient, String databaseName, String path) in C:\Builds\RavenDB-Stable-4.1\src\Raven.Server\Documents\Handlers\Debugging\ServerWideDebugInfoPackageHandler.cs:line 311

感谢您提供任何类型的调查提示。

更新: 将编译器和 Tomcat JVM 移回 Java 1.8 时也是如此。

【问题讨论】:

  • 我会开始投资的第一件事是项目中使用的底层框架和库的兼容性(与 Java-11)。然后进一步确保类似的配置是否适用于以前的 LTS(Java-8)
  • @nullpointer:在我升级到 Java 11 之前一切正常。我想在我拥有的众多依赖项中(即使它们已通过 Java 11 认证)至少其中一个正在播放犯规。

标签: linux jax-rs ravendb tomcat8 java-11


【解决方案1】:

它似乎与 Java 11(或 1.8)无关,只是它让我的注意力转移到了关闭 CloseableIterator&lt;StreamResult&lt;AdministrativeArea&gt;&gt; results; 添加一个简单的 results.close(); 之后,一切似乎都可以正常工作。如果这不是解决方案,我会回来更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多