【问题标题】:Does camel use an implicit read lock for files?骆驼是否对文件使用隐式读锁?
【发布时间】:2017-03-29 14:24:35
【问题描述】:

我正在使用 Camel File 组件来消费一个文件,如下所示:

<from uri="file:myDir?noop=true&amp;filter=myFilter&amp;scheduler=quartz2&amp;scheduler.cron={{schedule}}/>

源位置是只读的。 Camel File documentation 说,默认情况下它不会使用读锁。

但是,我在运行此代码时遇到了权限被拒绝异常。

端点[file://myFile?filter=myFilter&idempotent=true&noop=true&scheduler=quartz2&scheduler.cron={{mySchedule}} 无法开始处理文件:GenericFile[myDir\myFile] 由于:访问 被拒绝。原因:[java.io.IOException - 访问被拒绝]

堆栈跟踪 java.io.IOException:权限被拒绝 java.io.UnixFileSystem.createFileExclusively(Native Method)[:1.8.0_66] 在 java.io.File.createNewFile(File.java:1012)[:1.8.0_66] 在 org.apache.camel.util.FileUtil.createNewFile(FileUtil.java:587)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.MarkerFileExclusiveReadLockStrategy.acquireExclusiveReadLock(MarkerFileExclusiveReadLockStrategy.java:71)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport.begin(GenericFileProcessStrategySupport.java:49)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.begin(GenericFileRenameProcessStrategy.java:35)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:352)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:211)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:175)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)[org.apache.camel:camel-core:2.15.1.redhat-621090 com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2] 在 org.apache.camel.pollconsumer.quartz2.QuartzScheduledPollConsumerJob.execute(QuartzScheduledPollConsumerJob.java:59)[org.apache.camel:camel-quartz2:2.15.1.redhat-621090] 在 org.quartz.core.JobRunShell.run(JobRunShell.java:202)[org.quartz-scheduler:quartz:2.2.1] 在 org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)[org.quartz-scheduler:quartz:2.2.1]

从堆栈跟踪看来,camel 正在尝试创建 readLock,并且由于缺少权限而导致异常。

所以,我的问题是

  • 为什么骆驼使用锁,即使读锁的默认值为none
  • 如果这是预期行为,如何从我没有写入权限的只读位置使用文件?

更新

我尝试按照其中一个答案的建议将readLockMarkingFile 设置为false,但这并没有解决问题。所以,我明确地将readLock 设置为none。现在,它正在工作。不知道,为什么 readLock 默认不是 none 文档中提到的。

【问题讨论】:

    标签: java apache-camel readonly jbossfuse file-read


    【解决方案1】:

    readLock 选项只决定骆驼是否会尝试获取文件的独占读锁。还有另一个名为“readLockMarkerFile”的选项默认为true,将该选项设置为false,你应该没问题。

    <from uri="file:myDir?noop=true&amp;filter=myFilter&amp;scheduler=quartz2&amp;scheduler.cron={{schedule}}&amp;readLockMarkerFile=false/>
    

    【讨论】:

    • 我尝试将 readLockMarkerFile 设置为 false。但这没有用。然后我尝试显式设置 readLock=none,这很有效。看来,在这种情况下,骆驼正在使用重命名 readLock,但我不知道为什么。
    【解决方案2】:

    虽然这不能直接回答您的问题,但我使用了文件观察程序查找的触发文件(0 字节)。然后,您的路线将适用于触发器作为伴侣的实际文件。触发器文件被移动到子目录 /parent/.camel ,因此它不会再次处理。尽管我们注意到路由会尝试在分布式环境中“拾取”实际文件,在该环境中运行路由的服务器不止一台。

    【讨论】:

      【解决方案3】:

      我也遇到过这个问题,文档说明参数的默认值是none,但实际上使用的是markerFile。要解决此问题,您必须明确指定此参数readLock=none(camel-version 2.20.2)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-21
        • 1970-01-01
        • 2020-07-04
        • 2014-12-14
        相关资源
        最近更新 更多