簡體   English   中英

在MongoDB Java驅動程序中的聚合管道執行中設置超時的行為是什么?

[英]What is the behavior of setting timeout in aggregation pipeline execution in MongoDB Java Driver?

我需要在聚合管道執行上設置超時。 我正在使用MongoDB Java驅動程序3.2。 我知道我必須使用以下代碼:

collection.aggregate(pipeline).maxTime(10, TimeUnit.SECONDS);

問題是一旦達到超時,我將無法在任何地方找到程序的行為。 它拋出異常了嗎? 它會以null提示方式終止並返回null結果嗎?

官方的MongoDB文檔什么也沒說(請參見cursor.maxTimeMS() )。 此外,Java API也沒有引用任何特定的行為(請參見maxTime )。

這怎么可能?!

好的,我知道了。 如果聚合管道的執行超過通過方法maxTime表示的時間,則會引發com.mongodb.MongoExecutionTimeoutException

異常的堆棧跟蹤如下:

com.mongodb.MongoExecutionTimeoutException: operation exceeded time limit

    at com.mongodb.connection.ProtocolHelper.createSpecialException(ProtocolHelper.java:157)
    at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:111)
    at com.mongodb.connection.CommandProtocol.execute(CommandProtocol.java:114)
    at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:159)
    at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:286)
    at com.mongodb.connection.DefaultServerConnection.command(DefaultServerConnection.java:173)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:215)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:206)
    at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:112)
    at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:227)
    at com.mongodb.operation.AggregateOperation$1.call(AggregateOperation.java:223)
    at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:239)
    at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:212)
    at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:223)
    at com.mongodb.operation.AggregateOperation.execute(AggregateOperation.java:65)
    at com.mongodb.Mongo.execute(Mongo.java:772)
    at com.mongodb.Mongo$2.execute(Mongo.java:759)

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM