首页 > 解决方案 > 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

解决方案


marklogic-java-api Github 存储库中提交了一个错误。


推荐阅读