HADOOP-8110. Fix trash checkpoint collisions (Jason Lowe via daryn)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1356918 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
84c073b341
commit
3131e49840
|
@ -550,6 +550,8 @@ Release 0.23.3 - UNRELEASED
|
||||||
|
|
||||||
HADOOP-8535. Cut hadoop build times in half (Job Eagles via bobby)
|
HADOOP-8535. Cut hadoop build times in half (Job Eagles via bobby)
|
||||||
|
|
||||||
|
HADOOP-8110. Fix trash checkpoint collisions (Jason Lowe via daryn)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
BUG FIXES
|
BUG FIXES
|
||||||
|
|
|
@ -35,6 +35,7 @@ import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
import org.apache.hadoop.conf.Configuration;
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.conf.Configured;
|
import org.apache.hadoop.conf.Configured;
|
||||||
|
import org.apache.hadoop.fs.Options.Rename;
|
||||||
import org.apache.hadoop.fs.permission.FsAction;
|
import org.apache.hadoop.fs.permission.FsAction;
|
||||||
import org.apache.hadoop.fs.permission.FsPermission;
|
import org.apache.hadoop.fs.permission.FsPermission;
|
||||||
|
|
||||||
|
@ -148,21 +149,32 @@ public class TrashPolicyDefault extends TrashPolicy {
|
||||||
new IOException("Failed to move to trash: "+path).initCause(cause);
|
new IOException("Failed to move to trash: "+path).initCause(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void createCheckpoint() throws IOException {
|
public void createCheckpoint() throws IOException {
|
||||||
if (!fs.exists(current)) // no trash, no checkpoint
|
if (!fs.exists(current)) // no trash, no checkpoint
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Path checkpoint;
|
Path checkpointBase;
|
||||||
synchronized (CHECKPOINT) {
|
synchronized (CHECKPOINT) {
|
||||||
checkpoint = new Path(trash, CHECKPOINT.format(new Date()));
|
checkpointBase = new Path(trash, CHECKPOINT.format(new Date()));
|
||||||
|
}
|
||||||
|
Path checkpoint = checkpointBase;
|
||||||
|
|
||||||
|
int attempt = 0;
|
||||||
|
while (true) {
|
||||||
|
try {
|
||||||
|
fs.rename(current, checkpoint, Rename.NONE);
|
||||||
|
break;
|
||||||
|
} catch (FileAlreadyExistsException e) {
|
||||||
|
if (++attempt > 1000) {
|
||||||
|
throw new IOException("Failed to checkpoint trash: "+checkpoint);
|
||||||
|
}
|
||||||
|
checkpoint = checkpointBase.suffix("-" + attempt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs.rename(current, checkpoint)) {
|
LOG.info("Created trash checkpoint: "+checkpoint.toUri().getPath());
|
||||||
LOG.info("Created trash checkpoint: "+checkpoint.toUri().getPath());
|
|
||||||
} else {
|
|
||||||
throw new IOException("Failed to checkpoint trash: "+checkpoint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue