Esempio n. 1
0
        /// <summary>
        /// Analyze backup storage directories for consistency.<br />
        /// Recover from incomplete checkpoints if required.<br />
        /// Read VERSION and fstime files if exist.<br />
        /// Do not load image or edits.
        /// </summary>
        /// <exception cref="System.IO.IOException">if the node should shutdown.</exception>
        internal virtual void RecoverCreateRead()
        {
            for (IEnumerator <Storage.StorageDirectory> it = storage.DirIterator(); it.HasNext
                     ();)
            {
                Storage.StorageDirectory sd = it.Next();
                Storage.StorageState     curState;
                try
                {
                    curState = sd.AnalyzeStorage(HdfsServerConstants.StartupOption.Regular, storage);
                    switch (curState)
                    {
                    case Storage.StorageState.NonExistent:
                    {
                        // sd is locked but not opened
                        // fail if any of the configured storage dirs are inaccessible
                        throw new InconsistentFSStateException(sd.GetRoot(), "checkpoint directory does not exist or is not accessible."
                                                               );
                    }

                    case Storage.StorageState.NotFormatted:
                    {
                        // for backup node all directories may be unformatted initially
                        Log.Info("Storage directory " + sd.GetRoot() + " is not formatted.");
                        Log.Info("Formatting ...");
                        sd.ClearDirectory();
                        // create empty current
                        break;
                    }

                    case Storage.StorageState.Normal:
                    {
                        break;
                    }

                    default:
                    {
                        // recovery is possible
                        sd.DoRecover(curState);
                        break;
                    }
                    }
                    if (curState != Storage.StorageState.NotFormatted)
                    {
                        // read and verify consistency with other directories
                        storage.ReadProperties(sd);
                    }
                }
                catch (IOException ioe)
                {
                    sd.Unlock();
                    throw;
                }
            }
        }
 /// <summary>Format a block pool slice storage.</summary>
 /// <param name="bpSdir">the block pool storage</param>
 /// <param name="nsInfo">the name space info</param>
 /// <exception cref="System.IO.IOException">Signals that an I/O exception has occurred.
 ///     </exception>
 private void Format(Storage.StorageDirectory bpSdir, NamespaceInfo nsInfo)
 {
     Log.Info("Formatting block pool " + blockpoolID + " directory " + bpSdir.GetCurrentDir
                  ());
     bpSdir.ClearDirectory();
     // create directory
     this.layoutVersion = HdfsConstants.DatanodeLayoutVersion;
     this.cTime         = nsInfo.GetCTime();
     this.namespaceID   = nsInfo.GetNamespaceID();
     this.blockpoolID   = nsInfo.GetBlockPoolID();
     WriteProperties(bpSdir);
 }
Esempio n. 3
0
 /// <exception cref="System.IO.IOException"/>
 internal virtual void Format(NamespaceInfo nsInfo)
 {
     SetStorageInfo(nsInfo);
     Log.Info("Formatting journal " + sd + " with nsid: " + GetNamespaceID());
     // Unlock the directory before formatting, because we will
     // re-analyze it after format(). The analyzeStorage() call
     // below is reponsible for re-locking it. This is a no-op
     // if the storage is not currently locked.
     UnlockAll();
     sd.ClearDirectory();
     WriteProperties(sd);
     CreatePaxosDir();
     AnalyzeStorage();
 }
Esempio n. 4
0
            /// <summary>Analyze checkpoint directories.</summary>
            /// <remarks>
            /// Analyze checkpoint directories.
            /// Create directories if they do not exist.
            /// Recover from an unsuccessful checkpoint if necessary.
            /// </remarks>
            /// <exception cref="System.IO.IOException"/>
            internal virtual void RecoverCreate(bool format)
            {
                storage.AttemptRestoreRemovedStorage();
                storage.UnlockAll();
                for (IEnumerator <Storage.StorageDirectory> it = storage.DirIterator(); it.HasNext
                         ();)
                {
                    Storage.StorageDirectory sd = it.Next();
                    bool isAccessible           = true;
                    try
                    {
                        // create directories if don't exist yet
                        if (!sd.GetRoot().Mkdirs())
                        {
                        }
                    }
                    catch (SecurityException)
                    {
                        // do nothing, directory is already created
                        isAccessible = false;
                    }
                    if (!isAccessible)
                    {
                        throw new InconsistentFSStateException(sd.GetRoot(), "cannot access checkpoint directory."
                                                               );
                    }
                    if (format)
                    {
                        // Don't confirm, since this is just the secondary namenode.
                        Log.Info("Formatting storage directory " + sd);
                        sd.ClearDirectory();
                    }
                    Storage.StorageState curState;
                    try
                    {
                        curState = sd.AnalyzeStorage(HdfsServerConstants.StartupOption.Regular, storage);
                        switch (curState)
                        {
                        case Storage.StorageState.NonExistent:
                        {
                            // sd is locked but not opened
                            // fail if any of the configured checkpoint dirs are inaccessible
                            throw new InconsistentFSStateException(sd.GetRoot(), "checkpoint directory does not exist or is not accessible."
                                                                   );
                        }

                        case Storage.StorageState.NotFormatted:
                        {
                            break;
                        }

                        case Storage.StorageState.Normal:
                        {
                            // it's ok since initially there is no current and VERSION
                            // Read the VERSION file. This verifies that:
                            // (a) the VERSION file for each of the directories is the same,
                            // and (b) when we connect to a NN, we can verify that the remote
                            // node matches the same namespace that we ran on previously.
                            storage.ReadProperties(sd);
                            break;
                        }

                        default:
                        {
                            // recovery is possible
                            sd.DoRecover(curState);
                            break;
                        }
                        }
                    }
                    catch (IOException ioe)
                    {
                        sd.Unlock();
                        throw;
                    }
                }
            }