public virtual void TestConvertStoragInfo() { StorageInfo info = GetStorageInfo(HdfsServerConstants.NodeType.NameNode); HdfsProtos.StorageInfoProto infoProto = PBHelper.Convert(info); StorageInfo info2 = PBHelper.Convert(infoProto, HdfsServerConstants.NodeType.NameNode ); NUnit.Framework.Assert.AreEqual(info.GetClusterID(), info2.GetClusterID()); NUnit.Framework.Assert.AreEqual(info.GetCTime(), info2.GetCTime()); NUnit.Framework.Assert.AreEqual(info.GetLayoutVersion(), info2.GetLayoutVersion() ); NUnit.Framework.Assert.AreEqual(info.GetNamespaceID(), info2.GetNamespaceID()); }
/// <summary> /// Return true if this storage dir can roll back to the previous storage /// state, false otherwise. /// </summary> /// <remarks> /// Return true if this storage dir can roll back to the previous storage /// state, false otherwise. The NN will refuse to run the rollback operation /// unless at least one JM or fsimage storage directory can roll back. /// </remarks> /// <param name="storage">the storage info for the current state</param> /// <param name="prevStorage">the storage info for the previous (unupgraded) state</param> /// <param name="targetLayoutVersion">the layout version we intend to roll back to</param> /// <returns>true if this JM can roll back, false otherwise.</returns> /// <exception cref="System.IO.IOException">in the event of error</exception> internal static bool CanRollBack(Storage.StorageDirectory sd, StorageInfo storage , StorageInfo prevStorage, int targetLayoutVersion) { FilePath prevDir = sd.GetPreviousDir(); if (!prevDir.Exists()) { // use current directory then Log.Info("Storage directory " + sd.GetRoot() + " does not contain previous fs state." ); // read and verify consistency with other directories storage.ReadProperties(sd); return(false); } // read and verify consistency of the prev dir prevStorage.ReadPreviousVersionProperties(sd); if (prevStorage.GetLayoutVersion() != targetLayoutVersion) { throw new IOException("Cannot rollback to storage version " + prevStorage.GetLayoutVersion () + " using this version of the NameNode, which uses storage version " + targetLayoutVersion + ". " + "Please use the previous version of HDFS to perform the rollback."); } return(true); }
// 0 // 1 // 2 // 3 // 4 // 5 // 6 // 7 // 8 // 9 // 10 // 11 // 12 // 13 // 14 // 15 // 16 // 17 // Test with invalid clusterId // 18 // Test with invalid block pool Id // 19 /// <summary> /// Determines if the given Namenode version and Datanode version /// are compatible with each other. /// </summary> /// <remarks> /// Determines if the given Namenode version and Datanode version /// are compatible with each other. Compatibility in this case mean /// that the Namenode and Datanode will successfully start up and /// will work together. The rules for compatibility, /// taken from the DFS Upgrade Design, are as follows: /// <pre> /// <ol> /// <li>Check 0: Datanode namespaceID != Namenode namespaceID the startup fails /// </li> /// <li>Check 1: Datanode clusterID != Namenode clusterID the startup fails /// </li> /// <li>Check 2: Datanode blockPoolID != Namenode blockPoolID the startup fails /// </li> /// <li>Check 3: The data-node does regular startup (no matter which options /// it is started with) if /// softwareLV == storedLV AND /// DataNode.FSSCTime == NameNode.FSSCTime /// </li> /// <li>Check 4: The data-node performs an upgrade if it is started without any /// options and /// |softwareLV| > |storedLV| OR /// (softwareLV == storedLV AND /// DataNode.FSSCTime < NameNode.FSSCTime) /// </li> /// <li>NOT TESTED: The data-node rolls back if it is started with /// the -rollback option and /// |softwareLV| >= |previous.storedLV| AND /// DataNode.previous.FSSCTime <= NameNode.FSSCTime /// </li> /// <li>Check 5: In all other cases the startup fails.</li> /// </ol> /// </pre> /// </remarks> internal virtual bool IsVersionCompatible(TestDFSStartupVersions.StorageData namenodeSd , TestDFSStartupVersions.StorageData datanodeSd) { StorageInfo namenodeVer = namenodeSd.storageInfo; StorageInfo datanodeVer = datanodeSd.storageInfo; // check #0 if (namenodeVer.GetNamespaceID() != datanodeVer.GetNamespaceID()) { Log.Info("namespaceIDs are not equal: isVersionCompatible=false"); return(false); } // check #1 if (!namenodeVer.GetClusterID().Equals(datanodeVer.GetClusterID())) { Log.Info("clusterIDs are not equal: isVersionCompatible=false"); return(false); } // check #2 if (!namenodeSd.blockPoolId.Equals(datanodeSd.blockPoolId)) { Log.Info("blockPoolIDs are not equal: isVersionCompatible=false"); return(false); } // check #3 int softwareLV = HdfsConstants.DatanodeLayoutVersion; int storedLV = datanodeVer.GetLayoutVersion(); if (softwareLV == storedLV && datanodeVer.GetCTime() == namenodeVer.GetCTime()) { Log.Info("layoutVersions and cTimes are equal: isVersionCompatible=true"); return(true); } // check #4 long absSoftwareLV = Math.Abs((long)softwareLV); long absStoredLV = Math.Abs((long)storedLV); if (absSoftwareLV > absStoredLV || (softwareLV == storedLV && datanodeVer.GetCTime () < namenodeVer.GetCTime())) { Log.Info("softwareLayoutVersion is newer OR namenode cTime is newer: isVersionCompatible=true" ); return(true); } // check #5 Log.Info("default case: isVersionCompatible=false"); return(false); }
public virtual int GetVersion() { // NodeRegistration return(storageInfo.GetLayoutVersion()); }