marklogic - QueryBatcher JobReport 错误失败号
问题描述
我正在使用 a 查询文档QueryBatcher
并使用 a 应用转换ApplyTransformListener
。在所有批次完成后,我想知道是否有任何批次失败。这JobReport
似乎是解决这个问题的方法。我的问题是 JobReport 总是报告每个批次都是成功的,即使有失败。出于测试目的,批量大小为 1,以便每个文档在一个批次中处理。
final ApplyTransformListener transformListener = new ApplyTransformListener()
.withApplyResult(ApplyTransformListener.ApplyResult.REPLACE)
.withTransform(new ServerTransform(transformName))
.onSuccess(batch -> {
if (log.isTraceEnabled()) {
for (String item : batch.getItems()) {
log.trace("Batch #{}: item {} successfully executed.", batch.getForestBatchNumber(), item);
}
}
log.debug("Batch #{}: finished executed.", batch.getForestBatchNumber());
})
.onFailure((batch, throwable) -> {
log.error("Batch #{}: failed.", batch.getForestBatchNumber(), throwable);
})
.onSkipped(batch -> Arrays.stream(batch.getItems())
.forEach(it -> log.warn("Skipped processing document {}.", it))
);
final QueryBatcher batcher = dmm.newQueryBatcher(queryDef)
.withBatchSize(batchSize)
.withConsistentSnapshot()
.onUrisReady(transformListener);
try {
final JobTicket jobTicket = dmm.startJob(batcher);
batcher.awaitCompletion();
final JobReport jobReport = dmm.getJobReport(jobTicket);
if (jobReport.getFailureBatchesCount() > 0) {
// expected to be at least 1
throw new MagicException(String.format("%d batches failed to executed.", jobReport.getFailureBatchesCount()));
}
dmm.stopJob(jobTicket);
log.debug("Successfully executed {} batches.", jobReport.getSuccessBatchesCount());
} catch (final Exception ex) {
System.out.println(ex);
}
这些是生成的日志:
11:04:10.950 [pool-2-thread-2] TRACE - Batch #1: item test/Cat.xml successfully executed.
11:04:10.950 [pool-2-thread-2] DEBUG - Batch #1: finished executed.
11:04:10.952 [pool-2-thread-1] TRACE - Batch #1: item test/Cat3.xml successfully executed.
11:04:10.952 [pool-2-thread-1] DEBUG - Batch #1: finished executed.
11:04:10.971 [pool-2-thread-3] ERROR - Batch #2: failed.
com.marklogic.client.FailedRequestException: Local message: failed to apply resource at internal/apply-transform: Internal Server Error. Server Message: error (err:FOER0000): . See the MarkLogic server error log for further detail.
at com.marklogic.client.impl.OkHttpServices.checkStatus(OkHttpServices.java:4395) ~[marklogic-client-api-4.2.0.jar:?]
at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3377) ~[marklogic-client-api-4.2.0.jar:?]
at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3323) ~[marklogic-client-api-4.2.0.jar:?]
at com.marklogic.client.impl.OkHttpServices.postResource(OkHttpServices.java:3314) ~[marklogic-client-api-4.2.0.jar:?]
at com.marklogic.client.datamovement.ApplyTransformListener.processEvent(ApplyTransformListener.java:144) [marklogic-client-api-4.2.0.jar:?]
at com.marklogic.client.datamovement.impl.QueryBatcherImpl$QueryTask.run(QueryBatcherImpl.java:674) [marklogic-client-api-4.2.0.jar:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_222]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_222]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_222]
11:04:10.974 [main] DEBUG - Successfully executed 3/3 batches.
如您所见,确实有一个错误引发并登录到我的onFailure
侦听器中。
转换非常简单,仅用于测试目的。如果某个值不等于 1,则会引发错误:
xquery version "1.0-ml";
module namespace transform = "http://marklogic.com/rest-api/transform/magic-test/cat.xml";
declare function transform($context as map:map, $params as map:map, $content as document-node()) as document-node(){
if (xs:integer($content/cats/age) eq 1) then
document {
<cats>
{$content/cats/uri}
{$content/cats/age}
<name>Tiger</name>
</cats>
}
else fn:error()
};
这是我的数据的样子:
<cats>
<uri>test/Cat</uri>
<name>cat</name>
<age>1</age>
</cats>
<cats>
<uri>test/Cat2</uri>
<name>cat two</name>
<age>2</age>
</cats>
<cats>
<uri>test/Cat3</uri>
<name>cat three</name>
<age>1</age>
</cats>
我正在使用java-client-api:4.2.0
. 为什么jobReport.getFailureBatchesCount()
即使一批失败也不等于1?我是否需要另一个我不知道的 onFailure 侦听器?
解决方案
在marklogic-java-api Github 存储库中提交了一个错误。
推荐阅读
- reactjs - 如何使用 Typescript 验证异步 api 响应
- reactjs - 在 react-firebase-hooks/database 上对数据进行排序
- blockchain - 交易在以太坊区块链浏览器上可见,但代币在 Metamask 钱包中不显示
- c++ - 编译器错误信息:没有使用未使用的类型名模板调用 FUNCTION(TYPES ARGS) 的匹配函数
- javascript - mCustomScrollbar 到达底部时不会滚动整个页面,为什么?
- arrays - 在一个元素处停止的循环和数组问题
- css - Vue.js 手写笔和作用域 css 不起作用
- python-3.x - 使用 CreatePseudoConsole 在 python 中创建 pty 管道的问题
- php - 如何向最终用户隐藏 php 错误详细信息
- python - 如何在条件中保存一个空变量,以便它不会在语句中省略一行,而是继续下一步?