2017-05-24 8 views
0

집계 파이프 라인 실행시 시간 제한을 설정해야합니다. MongoDB Java 드라이버 3.2를 사용하고 있습니다.MongoDB Java Driver에서 집계 파이프 라인 실행시 시간 초과를 설정하는 동작은 무엇입니까?

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

문제는 내가 시간이 초과되면 프로그램의 동작입니다 어디서나 손쉽게 찾을 수 없다는 것입니다 : 내가 사용해야하는 코드는 다음과 같다 것을 알고있다. 예외가 발생 했습니까? 자동으로 종료되어 null 결과를 반환합니까?

공식 MongoDB 문서에는 아무 것도 없습니다 (cursor.maxTimeMS() 참조). 또한 Java API는 특정 동작을 참조하지 않습니다 (maxTime 참조).

어떻게 가능합니까?!

+0

null iterable을 반환하기를 바랍니다. 테스트를 원할 경우, 즉시 제한 시간을 강제 할 수있는 매우 적은 시간을 입력하고 얻은 결과를 확인하십시오. –

+0

나는 노력했다. 전혀 아무것도하지 않는 것 같습니다. 시간 초과가 존중되지 않는 것 같습니다 : ( –

+0

) 작은 시간 초과로 null이 아닌 값을 반환했습니다? –

답변

0

좋아, 알겠습니다. 집계 파이프 라인의 실행이 메서드 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) 

는 희망이 도움이 :

이 예외의 스택 트레이스는 다음과 정확히이다.