boolean hasRemovedTmp = getRemovedTmp().exists(); boolean hasFinalizedTmp = getFinalizedTmp().exists(); boolean hasCheckpointTmp = getLastCheckpointTmp().exists();
if (prevCkptDir.exists()) deleteDir(prevCkptDir); rename(getLastCheckpointTmp(), prevCkptDir); return; case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current if (curDir.exists()) deleteDir(curDir); rename(getLastCheckpointTmp(), curDir); return; default:
protected void moveCurrent(StorageDirectory sd) throws IOException { File curDir = sd.getCurrentDir(); File tmpCkptDir = sd.getLastCheckpointTmp(); // mv current -> lastcheckpoint.tmp // only if current is formatted - has VERSION file if (sd.getVersionFile().exists()) { assert curDir.exists() : curDir + " directory must exist."; assert !tmpCkptDir.exists() : tmpCkptDir + " directory must not exist."; rename(curDir, tmpCkptDir); } // recreate current if (!curDir.exists() && !curDir.mkdir()) throw new IOException("Cannot create directory " + curDir); }
boolean hasRemovedTmp = getRemovedTmp().exists(); boolean hasFinalizedTmp = getFinalizedTmp().exists(); boolean hasCheckpointTmp = getLastCheckpointTmp().exists();
boolean hasRemovedTmp = getRemovedTmp().exists(); boolean hasFinalizedTmp = getFinalizedTmp().exists(); boolean hasCheckpointTmp = getLastCheckpointTmp().exists();
boolean hasRemovedTmp = getRemovedTmp().exists(); boolean hasFinalizedTmp = getFinalizedTmp().exists(); boolean hasCheckpointTmp = getLastCheckpointTmp().exists();
boolean hasRemovedTmp = getRemovedTmp().exists(); boolean hasFinalizedTmp = getFinalizedTmp().exists(); boolean hasCheckpointTmp = getLastCheckpointTmp().exists();
if (prevCkptDir.exists()) deleteDir(prevCkptDir); rename(getLastCheckpointTmp(), prevCkptDir); return; case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current if (curDir.exists()) deleteDir(curDir); rename(getLastCheckpointTmp(), curDir); return; default:
if (prevCkptDir.exists()) deleteDir(prevCkptDir); rename(getLastCheckpointTmp(), prevCkptDir); return; case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current if (curDir.exists()) deleteDir(curDir); rename(getLastCheckpointTmp(), curDir); return; default:
if (prevCkptDir.exists()) deleteDir(prevCkptDir); rename(getLastCheckpointTmp(), prevCkptDir); return; case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current if (curDir.exists()) deleteDir(curDir); rename(getLastCheckpointTmp(), curDir); return; default:
if (prevCkptDir.exists()) deleteDir(prevCkptDir); rename(getLastCheckpointTmp(), prevCkptDir); return; case RECOVER_CHECKPOINT: // mv lastcheckpoint.tmp -> current if (curDir.exists()) deleteDir(curDir); rename(getLastCheckpointTmp(), curDir); return; default:
/** * Prepare directories for a new checkpoint. * <p> * Rename <code>current</code> to <code>lastcheckpoint.tmp</code> * and recreate <code>current</code>. * @throws IOException */ void startCheckpoint() throws IOException { for(StorageDirectory sd : storageDirs) { File curDir = sd.getCurrentDir(); File tmpCkptDir = sd.getLastCheckpointTmp(); assert !tmpCkptDir.exists() : tmpCkptDir.getName() + " directory must not exist."; if(curDir.exists()) { // rename current to tmp rename(curDir, tmpCkptDir); } if (!curDir.mkdir()) throw new IOException("Cannot create directory " + curDir); } }
/** * Deletes the checkpoint file in given storage directory. * Moves lastcheckpoint.tmp -> current */ private void deleteCancelledChecpointDir(StorageDirectory sd, Collection<StorageDirectory> errorDirs) throws IOException { LOG.info("Reverting checkpoint for : " + sd.getCurrentDir()); try { File tmpCkptDir = sd.getLastCheckpointTmp(); File curDir = sd.getCurrentDir(); if (!tmpCkptDir.exists()) { LOG.warn("Reverting checkpoint - lastcheckpoint.tmp " + "does not exist for storage directory: " + sd); errorDirs.add(sd); return; } // remove current if (curDir.exists()) deleteDir(curDir); // rename lastcheckpoint.tmp -> current rename(tmpCkptDir, curDir); } catch (IOException e) { LOG.warn("Unable to revet checkpoint for : " + sd.getCurrentDir()); errorDirs.add(sd); } }
/** * Move {@code lastcheckpoint.tmp} to {@code previous.checkpoint} * * @see org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory# * getPreviousCheckpoint() * @see org.apache.hadoop.hdfs.server.common.Storage.StorageDirectory# * getLastCheckpointTmp() */ protected void moveLastCheckpoint(StorageDirectory sd) throws IOException { File tmpCkptDir = sd.getLastCheckpointTmp(); File prevCkptDir = sd.getPreviousCheckpoint(); // remove previous.checkpoint if (prevCkptDir.exists()) deleteDir(prevCkptDir); // rename lastcheckpoint.tmp -> previous.checkpoint if (tmpCkptDir.exists()) rename(tmpCkptDir, prevCkptDir); }
void endCheckpoint() throws IOException { for(StorageDirectory sd : storageDirs) { File tmpCkptDir = sd.getLastCheckpointTmp(); File prevCkptDir = sd.getPreviousCheckpoint(); // delete previous dir if (prevCkptDir.exists()) deleteDir(prevCkptDir); // rename tmp to previous if (tmpCkptDir.exists()) rename(tmpCkptDir, prevCkptDir); } }