我们正在运行Cascading,并将Sink Tap配置为存储在Amazon S3中,并且面临一些FileAlreadyExistsException(参见[1])。 这只是不时(1次约100)并且不可复制。
深入研究级联代码,我们发现BaseFlow.deleteSinksIfNotUpdate()调用了Hfs.deleteResource()(等等)。 顺便说一句,我们对沉默的NPE非常感兴趣(评论“当fs到达根目录时,黑客可以绕过npe”)。
从那里开始,我们用自己的Tap扩展了Hfs tap,在deleteResource()方法中添加更多动作(参见[2]),重试机制直接调用getFileSystem(conf).delete。
重试机制似乎带来了改进,但我们仍然有时会面临失败(参见[3]中的示例):听起来HDFS返回isDeleted = true,但直接询问文件夹是否存在,我们收到exists = true ,这不应该发生。当流程成功时,日志也会随机显示isDeleted true或false,这听起来像返回的值无关或不可信。
任何人都可以通过这样的行为带来自己的S3体验:“文件夹应该被删除,但它不是”?我们怀疑是S3问题,但它也可能是Cascading或HDFS吗?
我们在Hadoop Cloudera-cdh3u5和Cascading 2.0.1-wip-dev上运行。
[1]
org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory s3n://... already exists
at org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:132)
at com.twitter.elephantbird.mapred.output.DeprecatedOutputFormatWrapper.checkOutputSpecs(DeprecatedOutputFormatWrapper.java:75)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:923)
at org.apache.hadoop.mapred.JobClient$2.run(JobClient.java:882)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1278)
at org.apache.hadoop.mapred.JobClient.submitJobInternal(JobClient.java:882)
at org.apache.hadoop.mapred.JobClient.submitJob(JobClient.java:856)
at cascading.flow.hadoop.planner.HadoopFlowStepJob.internalNonBlockingStart(HadoopFlowStepJob.java:104)
at cascading.flow.planner.FlowStepJob.blockOnJob(FlowStepJob.java:174)
at cascading.flow.planner.FlowStepJob.start(FlowStepJob.java:137)
at cascading.flow.planner.FlowStepJob.call(FlowStepJob.java:122)
at cascading.flow.planner.FlowStepJob.call(FlowStepJob.java:42)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.j
[2]
@Override
public boolean deleteResource(JobConf conf) throws IOException {
LOGGER.info("Deleting resource {}", getIdentifier());
boolean isDeleted = super.deleteResource(conf);
LOGGER.info("Hfs Sink Tap isDeleted is {} for {}", isDeleted,
getIdentifier());
Path path = new Path(getIdentifier());
int retryCount = 0;
int cumulativeSleepTime = 0;
int sleepTime = 1000;
while (getFileSystem(conf).exists(path)) {
LOGGER
.info(
"Resource {} still exists, it should not... - I will continue to wait patiently...",
getIdentifier());
try {
LOGGER.info("Now I will sleep " + sleepTime / 1000
+ " seconds while trying to delete {} - attempt: {}",
getIdentifier(), retryCount + 1);
Thread.sleep(sleepTime);
cumulativeSleepTime += sleepTime;
sleepTime *= 2;
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER
.error(
"Interrupted while sleeping trying to delete {} with message {}...",
getIdentifier(), e.getMessage());
throw new RuntimeException(e);
}
if (retryCount == 0) {
getFileSystem(conf).delete(getPath(), true);
}
retryCount++;
if (cumulativeSleepTime > MAXIMUM_TIME_TO_WAIT_TO_DELETE_MS) {
break;
}
}
if (getFileSystem(conf).exists(path)) {
LOGGER
.error(
"We didn't succeed to delete the resource {}. Throwing now a runtime exception.",
getIdentifier());
throw new RuntimeException(
"Although we waited to delete the resource for "
+ getIdentifier()
+ ' '
+ retryCount
+ " iterations, it still exists - This must be an issue in the underlying storage system.");
}
return isDeleted;
}
[3]
INFO [pool-2-thread-15] (BaseFlow.java:1287) - [...] at least one sink is marked for delete
INFO [pool-2-thread-15] (BaseFlow.java:1287) - [...] sink oldest modified date: Wed Dec 31 23:59:59 UTC 1969
INFO [pool-2-thread-15] (HiveSinkTap.java:148) - Now I will sleep 1 seconds while trying to delete s3n://... - attempt: 1
INFO [pool-2-thread-15] (HiveSinkTap.java:130) - Deleting resource s3n://...
INFO [pool-2-thread-15] (HiveSinkTap.java:133) - Hfs Sink Tap isDeleted is true for s3n://...
ERROR [pool-2-thread-15] (HiveSinkTap.java:175) - We didn't succeed to delete the resource s3n://... Throwing now a runtime exception.
WARN [pool-2-thread-15] (Cascade.java:706) - [...] flow failed: ...
java.lang.RuntimeException: Although we waited to delete the resource for s3n://... 0 iterations, it still exists - This must be an issue in the underlying storage system.
at com.qubit.hive.tap.HiveSinkTap.deleteResource(HiveSinkTap.java:179)
at com.qubit.hive.tap.HiveSinkTap.deleteResource(HiveSinkTap.java:40)
at cascading.flow.BaseFlow.deleteSinksIfNotUpdate(BaseFlow.java:971)
at cascading.flow.BaseFlow.prepare(BaseFlow.java:733)
at cascading.cascade.Cascade$CascadeJob.call(Cascade.java:761)
at cascading.cascade.Cascade$CascadeJob.call(Cascade.java:710)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
答案 0 :(得分:2)
首先,仔细检查级联兼容性页面以获取支持的发行版。
http://www.cascading.org/support/compatibility/
注意列出了Amazon EMR,因为它们会定期运行兼容性测试并报告结果。
其次,S3是最终一致的文件系统。 HDFS不是。因此,关于HDFS行为的假设不会延续到针对S3存储数据。例如,重命名实际上是一个复制和删除。副本可能需要数小时。亚马逊修补了内部发行版,以适应许多不同之处。
第三,S3中没有目录。这是一个hack,并且由不同的S3接口支持(jets3t vs s3cmd vs ...)。考虑到先前的观点,这肯定是有问题的。
第四,网络延迟和可靠性至关重要,尤其是在与S3通信时。从历史上看,在使用EMR与标准EC2实例时,在S3上操作海量数据集时,我发现亚马逊网络的表现更好。我也相信他们是EMR的一个补丁,可以改善这里的问题。
所以我建议尝试运行EMR Apache Hadoop发行版,看看你的问题是否已经解决。
答案 1 :(得分:1)
在Hadoop上运行使用S3中的文件的任何作业时,必须牢记最终一致性的细微差别。
我帮助排除了许多应用程序的问题,这些应用程序被证明具有与删除相似的竞争条件作为根本问题 - 无论是在Cascading还是Hadoop流式传输中,还是直接用Java编写。
在完全删除给定的键/值对后,有一次讨论来自S3的通知。我没有跟上这个功能的位置。否则,最好是设计系统 - 无论是在级联中还是在使用S3的任何其他应用程序中 - 这样批处理工作流消耗或生成的数据都可以在HDFS或HBase或键/值框架中进行管理(例如,为此使用了Redis)。然后S3用于持久存储,但不用于中间数据。