/** * Check if the given storage directory comes from a version of Hadoop * prior to when the directory layout changed (ie 0.13). If this is * the case, this method throws an IOException. */ private void checkOldLayoutStorage(StorageDirectory sd) throws IOException { if (isPreUpgradableLayout(sd)) { checkVersionUpgradable(0); } }
@Override public StorageDirectory next() { StorageDirectory sd = getStorageDir(nextIndex); prevIndex = nextIndex; nextIndex++; if (dirType != null || !includeShared) { while (nextIndex < storageDirs.size()) { if (shouldReturnNextDir()) break; nextIndex++; } } return sd; }
LOG.info("Completing previous upgrade for storage directory {}", rootPath); rename(getPreviousTmp(), getPreviousDir()); return; case RECOVER_UPGRADE: // mv previous.tmp -> current rootPath); if (curDir.exists()) deleteDir(curDir); rename(getPreviousTmp(), curDir); return; case COMPLETE_ROLLBACK: // rm removed.tmp LOG.info("Completing previous rollback for storage directory {}", rootPath); deleteDir(getRemovedTmp()); return; case RECOVER_ROLLBACK: // mv removed.tmp -> current LOG.info("Recovering storage directory {} from previous rollback", rootPath); rename(getRemovedTmp(), curDir); return; case COMPLETE_FINALIZE: // rm finalized.tmp LOG.info("Completing previous finalize for storage directory {}", rootPath); deleteDir(getFinalizedTmp()); return; case COMPLETE_CHECKPOINT: // mv lastcheckpoint.tmp -> previous.checkpoint File prevCkptDir = getPreviousCheckpoint();
public void writeProperties(File to, StorageDirectory sd) throws IOException { if (to == null) { return; } Properties props = new Properties(); setPropertiesFromFields(props, sd); writeProperties(to, props); }
/** * Write all data storage files. * @throws IOException */ public void writeAll() throws IOException { this.layoutVersion = getServiceLayoutVersion(); for (Iterator<StorageDirectory> it = storageDirs.iterator(); it.hasNext();) { writeProperties(it.next()); } }
/** * Return iterator based on Storage Directory Type * This iterator selects entries in storageDirs of type dirType and returns * them via the Iterator */ public Iterator<StorageDirectory> dirIterator(StorageDirType dirType) { return dirIterator(dirType, true); }
@Override // NodeRegistration public String getRegistrationID() { return Storage.getRegistrationID(storageInfo); }
public NamespaceInfo(int nsID, String clusterID, String bpID, long cT) { this(nsID, clusterID, bpID, cT, Storage.getBuildVersion(), VersionInfo.getVersion()); }
throw new InconsistentFSStateException(prevSD.getRoot(), "Cannot rollback to a newer state.\nDatanode previous state: LV = " + prevInfo.getLayoutVersion() + " CTime = " + prevInfo.getCTime() + " is newer than the namespace state: LV = " + nsInfo.getLayoutVersion() + " CTime = " + nsInfo.getCTime()); rename(curDir, tmpDir); rename(prevDir, curDir);
@Override public void run() { try { deleteDir(tmpDir); } catch (IOException ex) { LOG.error("Finalize upgrade for {} failed.", dataDirPath, ex); } LOG.info("Finalize upgrade for {} is complete.", dataDirPath); }
private void checkConversionNeeded(StorageDirectory sd) throws IOException { if (isConversionNeeded(sd)) { //throw an exception checkVersionUpgradable(0); } }
/** * Throw appropriate exception during upgrade from 203, when editlog loading * could fail due to opcode conflicts. */ private void check203UpgradeFailure(int logVersion, Throwable e) throws IOException { // 0.20.203 version version has conflicting opcodes with the later releases. // The editlog must be emptied by restarting the namenode, before proceeding // with the upgrade. if (Storage.is203LayoutVersion(logVersion) && logVersion != HdfsServerConstants.NAMENODE_LAYOUT_VERSION) { String msg = "During upgrade failed to load the editlog version " + logVersion + " from release 0.20.203. Please go back to the old " + " release and restart the namenode. This empties the editlog " + " and saves the namespace. Resume the upgrade after this step."; throw new IOException(msg, e); } }
/** * Move the src file to the target using * {@link Storage#rename(File, File)}. * * @param volume target volume. null if unavailable. * @param src source path. * @param target target path. * @throws IOException */ public void rename( @Nullable FsVolumeSpi volume, File src, File target) throws IOException { final long begin = profilingEventHook.beforeMetadataOp(volume, MOVE); try { faultInjectorEventHook.beforeMetadataOp(volume, MOVE); Storage.rename(src, target); profilingEventHook.afterMetadataOp(volume, MOVE, begin); } catch(Exception e) { onFailure(volume, begin); throw e; } }
/** * Write properties to the VERSION file in the given storage directory. */ public void writeProperties(StorageDirectory sd) throws IOException { writeProperties(sd.getVersionFile(), sd); }
@Test(expected=IOException.class) public void testUpgradeFromPreUpgradeLVFails() throws IOException { // Upgrade from versions prior to Storage#LAST_UPGRADABLE_LAYOUT_VERSION // is not allowed Storage.checkVersionUpgradable(Storage.LAST_PRE_UPGRADE_LAYOUT_VERSION + 1); fail("Expected IOException is not thrown"); }
/** * Create a <code>version</code> file for namenode inside the specified parent * directory. If such a file already exists, it will be overwritten. * The given version string will be written to the file as the layout * version. None of the parameters may be null. * * @param parent directory where namenode VERSION file is stored * @param version StorageInfo to create VERSION file from * @param bpid Block pool Id * * @return the created version file */ public static File[] createNameNodeVersionFile(Configuration conf, File[] parent, StorageInfo version, String bpid) throws IOException { Storage storage = new NNStorage(conf, Collections.<URI>emptyList(), Collections.<URI>emptyList()); storage.setStorageInfo(version); File[] versionFiles = new File[parent.length]; for (int i = 0; i < parent.length; i++) { versionFiles[i] = new File(parent[i], "VERSION"); StorageDirectory sd = new StorageDirectory(parent[i].getParentFile()); storage.writeProperties(versionFiles[i], sd); } return versionFiles; }
public void addStorageDir(StorageDirectory sd) { super.addStorageDir(sd); }
/** * Return all entries in storageDirs, potentially excluding shared dirs. * @param includeShared whether or not to include shared dirs. * @return an iterator over the configured storage dirs. */ public Iterator<StorageDirectory> dirIterator(boolean includeShared) { return dirIterator(null, includeShared); }
@Override // NodeRegistration public String getRegistrationID() { return Storage.getRegistrationID(this); }
public NamespaceInfo(int nsID, String clusterID, String bpID, long cT, HAServiceState st) { this(nsID, clusterID, bpID, cT, Storage.getBuildVersion(), VersionInfo.getVersion()); this.state = st; }