private static bool TestResourceScenario(int numRedundantResources, int numRequiredResources
                                                 , int numFailedRedundantResources, int numFailedRequiredResources, int minimumRedundantResources
                                                 )
        {
            ICollection <CheckableNameNodeResource> resources = new AList <CheckableNameNodeResource
                                                                           >();

            for (int i = 0; i < numRedundantResources; i++)
            {
                CheckableNameNodeResource r = Org.Mockito.Mockito.Mock <CheckableNameNodeResource>
                                                  ();
                Org.Mockito.Mockito.When(r.IsRequired()).ThenReturn(false);
                Org.Mockito.Mockito.When(r.IsResourceAvailable()).ThenReturn(i >= numFailedRedundantResources
                                                                             );
                resources.AddItem(r);
            }
            for (int i_1 = 0; i_1 < numRequiredResources; i_1++)
            {
                CheckableNameNodeResource r = Org.Mockito.Mockito.Mock <CheckableNameNodeResource>
                                                  ();
                Org.Mockito.Mockito.When(r.IsRequired()).ThenReturn(true);
                Org.Mockito.Mockito.When(r.IsResourceAvailable()).ThenReturn(i_1 >= numFailedRequiredResources
                                                                             );
                resources.AddItem(r);
            }
            return(NameNodeResourcePolicy.AreResourcesAvailable(resources, minimumRedundantResources
                                                                ));
        }
示例#2
0
        /// <summary>
        /// Apply the given operation across all of the journal managers, disabling
        /// any for which the closure throws an IOException.
        /// </summary>
        /// <param name="closure">
        ///
        /// <see cref="JournalClosure"/>
        /// object encapsulating the operation.
        /// </param>
        /// <param name="status">message used for logging errors (e.g. "opening journal")</param>
        /// <exception cref="System.IO.IOException">If the operation fails on all the journals.
        ///     </exception>
        private void MapJournalsAndReportErrors(JournalSet.JournalClosure closure, string
                                                status)
        {
            IList <JournalSet.JournalAndStream> badJAS = Lists.NewLinkedList();

            foreach (JournalSet.JournalAndStream jas in journals)
            {
                try
                {
                    closure.Apply(jas);
                }
                catch (Exception t)
                {
                    if (jas.IsRequired())
                    {
                        string msg = "Error: " + status + " failed for required journal (" + jas + ")";
                        Log.Fatal(msg, t);
                        // If we fail on *any* of the required journals, then we must not
                        // continue on any of the other journals. Abort them to ensure that
                        // retry behavior doesn't allow them to keep going in any way.
                        AbortAllJournals();
                        // the current policy is to shutdown the NN on errors to shared edits
                        // dir. There are many code paths to shared edits failures - syncs,
                        // roll of edits etc. All of them go through this common function
                        // where the isRequired() check is made. Applying exit policy here
                        // to catch all code paths.
                        ExitUtil.Terminate(1, msg);
                    }
                    else
                    {
                        Log.Error("Error: " + status + " failed for (journal " + jas + ")", t);
                        badJAS.AddItem(jas);
                    }
                }
            }
            DisableAndReportErrorOnJournals(badJAS);
            if (!NameNodeResourcePolicy.AreResourcesAvailable(journals, minimumRedundantJournals
                                                              ))
            {
                string message = status + " failed for too many journals";
                Log.Error("Error: " + message);
                throw new IOException(message);
            }
        }
示例#3
0
 /// <summary>
 /// Returns true if there are no journals, all redundant journals are disabled,
 /// or any required journals are disabled.
 /// </summary>
 /// <returns>
 /// True if there no journals, all redundant journals are disabled,
 /// or any required journals are disabled.
 /// </returns>
 public virtual bool IsEmpty()
 {
     return(!NameNodeResourcePolicy.AreResourcesAvailable(journals, minimumRedundantJournals
                                                          ));
 }
示例#4
0
 /// <summary>
 /// Return true if disk space is available on at least one of the configured
 /// redundant volumes, and all of the configured required volumes.
 /// </summary>
 /// <returns>
 /// True if the configured amount of disk space is available on at
 /// least one redundant volume and all of the required volumes, false
 /// otherwise.
 /// </returns>
 public virtual bool HasAvailableDiskSpace()
 {
     return(NameNodeResourcePolicy.AreResourcesAvailable(volumes.Values, minimumRedundantVolumes
                                                         ));
 }