简体   繁体   English

Apache Camel:无法删除文件和锁定

[英]Apache Camel: failing to delete file and lock

I am using the Apache Camel File component to read from a local directory and upload to an AWS S3 bucket. 我正在使用Apache Camel File组件从本地目录读取并上传到AWS S3存储桶。 This route has worked flawlessly in the past, but is having issues with certain files now-a-days. 这条路线过去一直运行良好,但现在每天都会遇到某些文件的问题。

In my debug investigations thus far (3 days of misery), I have found that the route reaches the DelegateSyncProcessor class and does not have any exception set on the exchange (for reference see the relevant code of the previously mentioned class below). 在我迄今为止的调试调查中(3天的痛苦),我发现路由到达DelegateSyncProcessor类并且在交换机上没有任何异常集(有关参考,请参阅下面提到的类的相关代码)。 Considering there aren't any exceptions, I can't seem to figure out why the onCompletion() methods never fire for specific files. 考虑到没有任何例外,我似乎无法弄清楚为什么onCompletion()方法永远不会针对特定文件触发。 There weren't/aren't any exceptions for problematic files; 有问题的文件没有/没有任何例外; however, the file and the lock continue to exist after all the logic has executed (including the final transfer of the message to the .to() endpoint) hinting that there is some internal Camel issue. 但是,在所有逻辑执行完后(包括最终将消息传输到.to()端点),文件和锁继续存在,暗示存在一些内部Camel问题。 I suspect this because the route behaves normally in every aspect except the file and lock deletion. 我怀疑这是因为路径在除文件和锁删除之外的每个方面都表现正常。

After enabling debug logs for Camel, I was frustrated to see that there were no logs related to an error during the route execution. 在为Camel启用调试日志后,我很沮丧地看到在路由执行期间没有与错误相关的日志。 I would love to hear any advice about what could be happening under the hood. 我很想听听有关引擎盖下可能发生的事情的任何建议。

A few extra things to note: 还有一些需要注意的事项:

  • I am running camel 2.16.0 我正在运行骆驼2.16.0
  • No easily detectable issues were seen while debugging through the camel code. 通过camel代码进行调试时,没有看到容易发现的问题。
  • The logic in the .process() sections runs all the way through (some exceptions occurred, but they are properly handled. .process()部分中的逻辑一直运行(发生了一些异常,但它们已正确处理。

Update: 更新:

More debugging with debug logs enabled for camel yielded no results. 为camel启用调试日志的更多调试没有产生任何结果。 I have only found that the logic within my .process() code is the issue. 我只发现我的.process()代码中的逻辑是问题。 When the code takes too long to execute (even without exceptions), the file deletion fails. 当代码执行太长时(即使没有例外),文件删除失败。


Update 2: 更新2:

I found where the camel route actually falls apart. 我发现骆驼路线实际上已经分崩离析了。 The CamelEventLogger.java class completely fails while trying to "logEvent". 尝试“logEvent”时, CamelEventLogger.java类完全失败。 The related code to that class is added below. 下面添加了该类的相关代码。 When the code reaches matcher.find() , it times out. 当代码到达matcher.find() ,它会超时。

MyRouteClass.java: MyRouteClass.java:

from(importProcessingEndpoint)
        .convertBodyTo(byte[].class)
        .process((exchange) -> {
           // some logic here
        })
        .to(outgoingEndpoint)
        .threads(MAX_NUMBER_OF_CAMEL_THREADS)
        .process((exchange) -> {
           // some logic here
        })
        .log("Finished processing import file.")
        .to(outgoingEndpoint);

DelegateSyncProcessor.java: DelegateSyncProcessor.java:

@Override
public boolean process(Exchange exchange, AsyncCallback callback) {
    // force calling the sync method
    try {
        processor.process(exchange);
    } catch (Throwable e) {
        // must catch throwable so we catch all
        exchange.setException(e);
    } finally {
        // we are bridging a sync processor as async so callback with true
        callback.done(true);
    }
    return true;
}

CamelEventLogger.java CamelEventLogger.java

private void logEvent(final String label, final Exchange exchange, final Endpoint endpoint,
            final long elapsedTime, final boolean logTID) {
        Matcher matcher = PATTERN.matcher(extractMessage(exchange));
        if (matcher.find()) {
            //CHECKSTYLE:OFF
            String evtType = matcher.group(1);
            String evtName = matcher.group(2);
            String guid = matcher.group(3);
            String tid = matcher.group(4);
            //CHECKSTYLE:ON
            if (tid == null || !logTID) {
                tid = "";
            } else {
                tid = "intuit_tid=" + tid;
            }
            log.info(LOG_FORMAT, label, exchange.getExchangeId(), guid, evtName, evtType, endpoint, elapsedTime, tid);
        } else { // the message is not parseable, fall back to minimum log entry
            log.info("Event {} id={} {} elapsedTimeMs={}", label, exchange.getExchangeId(), endpoint, elapsedTime);
        }
    }

I was initially surprised that this wasn't a common problem with Camel, but after fixing it, I've come to realize that it is definitely a user error (albeit, an interesting one). 我最初感到惊讶的是,这不是Camel的常见问题,但在修复之后,我逐渐意识到这绝对是一个用户错误(尽管是一个有趣的错误)。

Having said that the problem is uncommon, Ill give my solution (hopefully it has some value to someone). 说完这个问题并不常见,我会给出我的解决方案(希望它对某人有一些价值)。

As mentioned above, my camel route has hanging and failing to delete the locking file and the message (which was a file in this case). 如上所述,我的camel路由已挂起并且无法删除锁定文件和消息(在这种情况下是一个文件)。 FOR THE PROBLEMATIC FILE MESSAGES (I want to highlight this because it was an intermittent issue), the debugger seemed to bring me down a road to where the thread started to hang. 对于有问题的文件消息(我想强调这是因为它是一个间歇性问题),调试器似乎让我走上了线程开始挂起的道路。 Here I realized that I was brought to a custom Camel Logging class. 在这里,我意识到我被带到了一个自定义的Camel Logging类。 The logging class would fail based on different inputs. 日志记录类将根据不同的输入失败。

How would my situation be helpful to anyone else? 我的情况对其他人有什么帮助? I'll describe a strategy for debugging when you get to situations like these. 当你遇到这样的情况时,我将描述一个调试策略。

If your camel route is behaving similarly, find a use case in which the route hangs, pause your debugger (after it has started hanging) and take a thread dump. 如果您的camel路由的行为类似,请找到路由挂起的用例,暂停调试器(在它开始挂起之后)并进行线程转储。 It is within this thread dump and stage within the paused debugger where you can back track a bit. 它位于暂停调试器中的此线程转储和阶段中,您可以在其中回溯一些位。 For me, I noticed that 10 or so frames/steps ago, I reached an odd class. 对我来说,我注意到前10帧左右,我达到了一个奇怪的阶级。 I set a debug point there and could see that it was problematic. 我在那里设置了一个调试点,可以看出它有问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM