Ejemplo n.º 1
0
        static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            int       result      = unchecked ((int)LinqToDryadException.E_FAIL);
            Exception e           = args.ExceptionObject as Exception;
            string    errorString = "Unknown exception";

            if (e != null)
            {
                result      = System.Runtime.InteropServices.Marshal.GetHRForException(e);
                errorString = e.ToString();
                DryadLogger.LogCritical(errorString);
                System.Threading.Thread.Sleep(10 * 1000);
            }
            DebugHelper.StopLogging(result, errorString, DateTime.Now.ToLocalTime(), dfsDirectory);

            if (Debugger.IsAttached)
            {
                Debugger.Break();
            }
            else
            {
                DrLogging.WriteMiniDump();
            }

            // We need to Exit, since other threads in the GM
            // are likely to still be running.
            Environment.Exit(result);
        }
Ejemplo n.º 2
0
        public bool ParseQueryXml(string queryPlanFileName, Query query)
        {
            XmlNode     version      = null;
            XmlDocument queryPlanDoc = new XmlDocument();

            //
            // Load query plan document
            //
            try
            {
                queryPlanDoc.Load(queryPlanFileName);
            }
            catch (Exception e)
            {
                DryadLogger.LogCritical(String.Format("Failed to load query plan: {0}: {1}", queryPlanFileName, e.ToString()));
                return(false);
            }

            //
            // Get DryadLinqVersion - absence used to indicate Argentia query plan
            //
            try
            {
                version = queryPlanDoc.DocumentElement.SelectSingleNode("DryadLinqVersion");
            }
            catch (System.Xml.XPath.XPathException e)
            {
                DryadLogger.LogCritical(String.Format("Failed to select node DryadLinqVersion from query plan: {0}: {1}", queryPlanFileName, e.ToString()));
                return(false);
            }

            if (version == null)
            {
                DryadLogger.LogCritical(String.Format("Missing element 'DryadLinqVersion' in query plan: {0}", queryPlanFileName));
                return(false);
            }

            //
            // Parse query plan XML doc into Query
            //
            try
            {
                ParseQueryXmlLinqToDryad(queryPlanDoc, query);
            }
            catch (Exception e)
            {
                DryadLogger.LogCritical(String.Format("Failed to parse query plan: {0}: {1}", queryPlanFileName, e.ToString()));
                return(false);
            }
Ejemplo n.º 3
0
        static int Main(string[] args)
        {
            Console.WriteLine("{0} starting up in {1}", Environment.CommandLine, Environment.CurrentDirectory);

            bool          waitForDebugger = false;
            List <string> tempArgs        = new List <string>();

            // Record start time so we can report it once logging has been initialized
            DateTime startTime = DateTime.Now.ToLocalTime();

            // Set unhandled exception handler to catch anything thrown from
            // Microsoft.Hpc.Query.GraphManager.dll
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);

            dfsDirectory = null;

            foreach (string arg in args)
            {
                if (String.Compare(arg, "--break", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    waitForDebugger = true;
                }
                else if (arg.StartsWith("--dfs="))
                {
                    dfsDirectory = DebugHelper.AddDfsJobDirectoryFromArgs(arg);
                }
                else
                {
                    tempArgs.Add(arg);
                }
            }
            args = tempArgs.ToArray();

            if (waitForDebugger)
            {
                DebugHelper.WaitForDebugger();
            }

            //
            // Configure tracing
            //
            DebugHelper.InitializeLogging(startTime);

            //
            // Run the Graph Manager
            //
            int    retCode     = 0;
            string errorString = null;

            try
            {
                LinqToDryadJM jm = new LinqToDryadJM();
                retCode = jm.Run(dfsDirectory, args, out errorString);
            }
            catch (Exception e)
            {
                retCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);
                if (retCode == 0)
                {
                    errorString = e.ToString();
                    DryadLogger.LogCritical(errorString);
                    retCode = unchecked ((int)LinqToDryadException.E_FAIL);
                }
                else
                {
                    errorString = String.Format("{0}: {1}", retCode, e);
                    DryadLogger.LogCritical(errorString);
                }
                System.Threading.Thread.Sleep(10 * 1000);
            }

            DebugHelper.StopLogging(retCode, errorString, DateTime.Now.ToLocalTime(), dfsDirectory);

            // NOTE: We don't want to log critical errors twice, so here we're assuming that
            // if the GM exited "gracefully" and returned an error code instead of throwing
            // an exception, that it has already logged the error.
            if (retCode != 0)
            {
                // If the Graph Manager already started executing, we need to exit the process.
                // Exiting the thread (returning from Main) will not necessarily cause the GM's
                // worker threads to exit

                // TODO: Consider deleting temp output stream from DSC
                // requires that we have access to the URI at this point, though
                Environment.Exit(retCode);
            }

            //
            // Cleanup all vertex tasks in case any became
            // unreachable.
            //

            return(retCode);
        }
Ejemplo n.º 4
0
        public bool ParseCommandLineFlags(string[] args)
        {
            bool retVal = true;

            for (int index = 0; index < args.Length; index++)
            {
                string            arg    = args[index].Substring(args[index].IndexOf("-") + 1);
                OptionDescription option = null;
                m_optionMap.TryGetValue(arg, out option);
                if (option == null)
                {
                    retVal = false;
                    break;
                }
                int optionIndex = option.m_optionIndex;

                switch (optionIndex)
                {
                case (int)DryadLINQAppOptions.BDJAO_AMD64:
                case (int)DryadLINQAppOptions.BDJAO_I386:
                case (int)DryadLINQAppOptions.BDJAO_Retail:
                case (int)DryadLINQAppOptions.BDJAO_Debug:
                    break;

                case (int)DryadLINQAppOptions.DNAO_MaxAggregateInputs:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        int maxInputs;
                        if (!Int32.TryParse(args[index + 1], out maxInputs))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as an integer.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_maxAggregateInputs = maxInputs;
                            index++;
                        }
                    }
                    break;

                case (int)DryadLINQAppOptions.DNAO_MaxAggregateFilterInputs:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        int maxInputs;
                        if (!Int32.TryParse(args[index + 1], out maxInputs))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as an integer.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_maxAggregateFilterInputs = maxInputs;
                            index++;
                        }
                    }
                    break;


                case (int)DryadLINQAppOptions.DNAO_AggregateThreshold:
                    if ((index + 1) >= args.Length)
                    {
                        DryadLogger.LogCritical(String.Format("The argument for option '{0}' was missing.\n", args[index]));
                        retVal = false;
                    }
                    else
                    {
                        UInt64 threshold;
                        if (!UInt64.TryParse(args[index + 1], out threshold))
                        {
                            DryadLogger.LogCritical(String.Format("The argument '{0}' for option '{1}' could not be parsed as a UIN64.\n", args[index + 1], args[index]));
                            retVal = false;
                        }
                        else
                        {
                            m_aggregateThreshold = threshold;
                            index++;
                        }
                    }
                    break;

                case (int)DryadLINQAppOptions.DNAO_NoClusterAffinity:
                    m_clusterAffinity = false;
                    break;

                default:
                    DryadLogger.LogCritical(String.Format("Unknown command-line option {0}\n", optionIndex));
                    retVal = false;
                    break;
                }
            }

            if (!retVal)
            {
                PrintUsage(args[0]);
            }
            return(retVal);
        }
Ejemplo n.º 5
0
        //
        // Main Dryad LINQ execution stuff
        //
        public int ExecLinqToDryad(Uri dfsDirectory, string[] args, out string errorString)
        {
            //
            // must be at least two arguments (program name and query XML file name)
            //
            if (args.Length < 2)
            {
                errorString = "Must provide at least query XML file name and VertexHost executable.";
                DryadLogger.LogCritical(errorString);
                return(-1);
            }

            //
            // break if --break is included in arguments (and eliminate it, as it is not known downstream)
            //
            if (ConsumeSingleArgument("--break", ref args))
            {
                DebugHelper.WaitForDebugger();
            }

            // this is where we ensure the right type of scheduler is registered
            Microsoft.Research.Dryad.LocalScheduler.Registration.Ensure();

            //
            // parse the XML input, producing a DryadLINQ Query
            //
            Query           query  = new Query();
            QueryPlanParser parser = new QueryPlanParser();

            if (!parser.ParseQueryXml(args[1], query))
            {
                errorString = "Invalid query plan";
                DryadLogger.LogCritical(errorString);
                return(-1);
            }

            //
            // upload the query plan to the job DFS directory for the benefit of debug tools
            //
            if (dfsDirectory != null)
            {
                DebugHelper.UploadToDfs(dfsDirectory, args[1]);
            }

            //
            // build internal app arguments
            //
            List <string> internalArgs = new List <string>();

            //
            // add the XmlExecHost args to the internal app arguments
            //
            foreach (string xmlExecHostArg in query.xmlExecHostArgs)

            {
                if (xmlExecHostArg == "--break")
                {
                    DebugHelper.WaitForDebugger();
                }
                else
                {
                    internalArgs.Add(xmlExecHostArg);
                }
            }

            //
            // combine internal arguments with any additional arguments received on the command line
            // don't include argv[0] and argv[1] (program name and query XML file name)
            //

            int internalArgc = (int)internalArgs.Count;
            int externalArgc = args.Length - 2;          // don't include argv[0] and argv[1]
            int combinedArgc = internalArgc + externalArgc;

            string[] combinedArgv = new string[combinedArgc];

            string msg = "";

            // internal arguments first
            for (int i = 0; i < internalArgc; i++)
            {
                combinedArgv[i] = internalArgs[i];
                msg            += String.Format("{0} ", combinedArgv[i]);
            }

            // then external arguments
            for (int i = 0; i < externalArgc; i++)
            {
                combinedArgv[i + internalArgc] = args[i + 2]; // don't include argv[0] and argv[1]

                msg += String.Format("{0} ", combinedArgv[i + internalArgc]);
            }
            DryadLogger.LogInformation(String.Format("Arguments: {0}", msg));

            string jobClass = "DryadLINQ";
            string exeName  = args[0];

            // create app and run it
            //
            DrGraphParameters p = DrDefaultParameters.Make(exeName, jobClass, query.enableSpeculativeDuplication);

            foreach (DrIReporter reporter in DebugHelper.Reporters())
            {
                p.m_reporters.Add(reporter);
            }
            p.m_intermediateCompressionMode = query.intermediateDataCompression;
            DrGraphExecutor graphExecutor = new DrGraphExecutor();
            DrGraph         graph         = graphExecutor.Initialize(p);

            if (graph == null)
            {
                errorString = "Failed to initialize Graph Executor";
                DryadLogger.LogCritical(errorString);
                return(-1);
            }
            DryadLINQApp app = new DryadLINQApp(graph);

            // Initialize with arguments
            app.SetXmlFileName(args[1]);
            if (!app.ParseCommandLineFlags(combinedArgv))
            {
                errorString = "Bad command-line options";
                DryadLogger.LogCritical(errorString);
                return(-1);
            }
            // Build graph from query plan
            GraphBuilder builder = new GraphBuilder();

            builder.BuildGraphFromQuery(app, query);

            // Run the app
            DryadLogger.LogInformation("Running the app");

            graphExecutor.Run();
            DrError exitStatus = graphExecutor.Join();

            DryadLogger.LogInformation("Finished running the app");

            if (exitStatus == null || exitStatus.m_code == 0)
            {
                FinalizeExecution(query, graph);
                DryadLogger.LogInformation("Application completed successfully.");
                errorString = null;
                return(0);
            }
            else
            {
                DryadLogger.LogCritical(String.Format("Application failed with error code 0x{0:X8}.\n", exitStatus.m_code));
                errorString = exitStatus.ToFullTextNative();
                return(exitStatus.m_code);
            }
        }