コード例 #1
0
ファイル: TrackerTask.cs プロジェクト: ashansa/mapNoReduce
        /*going to replace one slow task*/
        private void ReplaceSlowTasks(int nodeId)
        {
            if (!HasPendingTasks())
            {
                WorkerDetails     bestWorker    = null;
                FileSplitMetadata splitMetadata = null;
                int splitId = 0;
                lock (taskList)
                {
                    foreach (var pair in taskList)
                    {
                        /* later change this to have from suspended as well */
                        if (pair.Value.StatusType == StatusType.INPROGRESS)
                        {
                            splitId    = pair.Key;
                            bestWorker = GetBestWorker(pair.Value, nodeId);
                            if (bestWorker != null)
                            {
                                bestWorker.State = WorkerState.ABOUT_TO_BUSY;
                                string         url    = existingWorkerMap[taskList[splitId].WorkerId].Nodeurl;
                                IWorkerTracker worker = (IWorkerTracker)Activator.GetObject(typeof(IWorkerTracker), url);
                                worker.suspendTask(splitId);

                                //reschedule
                                splitMetadata = pair.Value.SplitMetadata;
                                taskList[splitId].StatusType = StatusType.INPROGRESS;
                                taskList[splitId].WorkerId   = bestWorker.Nodeid;
                                sendTaskToWorker(bestWorker.Nodeid, splitMetadata);
                            }
                        }
                    }
                }
            }
            else
            {
                readyForNewTask(nodeId);
            }
        }
コード例 #2
0
ファイル: TrackerTask.cs プロジェクト: ashansa/mapNoReduce
        internal Dictionary <StatusType, List <int> > getStatusForWorker(Dictionary <StatusType, List <int> > freezedWorkerStatus, int nodeId, string nodeURL)
        {
            //Worker has come back. first thing to do is add to worker map and notify others
            WorkerDetails workerObj = getWorker(nodeId, nodeURL);

            if (!existingWorkerMap.ContainsKey(nodeId))
            {
                existingWorkerMap.Add(nodeId, workerObj);
                Thread thread = new Thread(() => notifyWorkersAboutUnfreezed(nodeId, nodeURL));
                thread.Start();
            }

            //make him upto date
            List <Int32> inProgress      = new List <int>();
            List <Int32> sendToClient    = new List <int>();
            bool         isTaskAvailable = false;
            Dictionary <StatusType, List <int> > result = new Dictionary <StatusType, List <int> >();

            for (int i = 0; i < freezedWorkerStatus.Count; i++)
            {
                KeyValuePair <StatusType, List <int> > entry = freezedWorkerStatus.ElementAt(i);
                switch (entry.Key)
                {
                case StatusType.COMPLETED:
                    foreach (int split in entry.Value)
                    {
                        lock (taskList[split])
                        {
                            if (taskList[split].StatusType == StatusType.INPROGRESS || taskList[split].StatusType == StatusType.NOT_SEND_TO_WORKER)
                            {
                                if (taskList[split].StatusType == StatusType.INPROGRESS)
                                {
                                    string         url    = existingWorkerMap[taskList[split].WorkerId].Nodeurl;
                                    IWorkerTracker worker = (IWorkerTracker)Activator.GetObject(typeof(IWorkerTracker), url);
                                    worker.suspendTask(split);
                                }
                                taskList[split].WorkerId = nodeId;    //later will receive completed once result sent to client
                                sendToClient.Add(split);
                            }
                        }
                    }
                    break;

                case StatusType.NOT_STARTED:
                    foreach (int split in entry.Value)
                    {
                        lock (taskList[split])
                        {
                            if (taskList[split].StatusType == StatusType.INPROGRESS && taskList[split].WorkerId != nodeId && taskList[split].PercentageCompleted > Constants.jobReplaceBoundaryPercentage || taskList[split].StatusType == StatusType.COMPLETED)
                            {
                                isTaskAvailable = false;
                            }
                            else
                            {
                                inProgress.Add(split);
                                isTaskAvailable = true;
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }
            if (isTaskAvailable == false)
            {
                FileSplitMetadata newSplitData = getNextPendingSplitFromList(nodeId);
                if (newSplitData != null)
                {
                    sendTaskToWorker(nodeId, newSplitData);
                    existingWorkerMap[nodeId].State = WorkerState.BUSY;
                }
            }
            else
            {
                existingWorkerMap[nodeId].State = WorkerState.BUSY;
            }
            result.Add(StatusType.COMPLETED, sendToClient); //cmpare completed and ResultTask and remove from resulttask if not in
            result.Add(StatusType.NOT_STARTED, inProgress); //compare with split metatdata,and remove from metadata if not
            return(result);
        }