Exemple #1
0
 public void Stop()
 {
     if (runningState.Get() == false)
     {
         Log.D(Log.TagQuery, "%s: stop() called, but runningState is already false.  Ignoring."
               , this);
         return;
     }
     else
     {
         Log.D(Log.TagQuery, "%s: stop() called", this);
         runningState.Set(false);
     }
     if (observing)
     {
         observing = false;
         GetDatabase().RemoveChangeListener(this);
     }
     // slight diversion from iOS version -- cancel the queryFuture
     // regardless of the willUpdate value, since there can be an update in flight
     // with willUpdate set to false.  was needed to make testLiveQueryStop() unit test pass.
     if (queryFuture != null)
     {
         bool cancelled = queryFuture.Cancel(true);
         Log.V(Log.TagQuery, "%s: cancelled queryFuture %s, returned: %s", this, queryFuture
               , cancelled);
     }
     if (rerunUpdateFuture != null)
     {
         bool cancelled = rerunUpdateFuture.Cancel(true);
         Log.D(Log.TagQuery, "%s: cancelled rerunUpdateFuture %s, returned: %s", this, rerunUpdateFuture
               , cancelled);
     }
 }
Exemple #2
0
 public bool Cancel()
 {
     return(Action == null &&
            (Actions == null || Actions.Count == 0) &&
            Future != null &&
            Future.Cancel(false));
 }
Exemple #3
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Close()
 {
     if (state.CompareAndSet(ChildReaper.State.Started, ChildReaper.State.Closed))
     {
         CloseableUtils.CloseQuietly(reaper);
         task.Cancel(true);
     }
 }
            /*
             * Uber-AM lifecycle/ordering ("normal" case):
             *
             * - [somebody] sends TA_ASSIGNED
             *   - handled by ContainerAssignedTransition (TaskAttemptImpl.java)
             *     - creates "remoteTask" for us == real Task
             *     - sends CONTAINER_REMOTE_LAUNCH
             *     - TA: UNASSIGNED -> ASSIGNED
             * - CONTAINER_REMOTE_LAUNCH handled by LocalContainerLauncher (us)
             *   - sucks "remoteTask" out of TaskAttemptImpl via getRemoteTask()
             *   - sends TA_CONTAINER_LAUNCHED
             *     [[ elsewhere...
             *       - TA_CONTAINER_LAUNCHED handled by LaunchedContainerTransition
             *         - registers "remoteTask" with TaskAttemptListener (== umbilical)
             *         - NUKES "remoteTask"
             *         - sends T_ATTEMPT_LAUNCHED (Task: SCHEDULED -> RUNNING)
             *         - TA: ASSIGNED -> RUNNING
             *     ]]
             *   - runs Task (runSubMap() or runSubReduce())
             *     - TA can safely send TA_UPDATE since in RUNNING state
             */
            // doneWithMaps and finishedSubMaps are accessed from only
            // one thread. Therefore, no need to make them volatile.
            public virtual void Run()
            {
                ContainerLauncherEvent @event = null;
                // Collect locations of map outputs to give to reduces
                IDictionary <TaskAttemptID, MapOutputFile> localMapFiles = new Dictionary <TaskAttemptID
                                                                                           , MapOutputFile>();

                // _must_ either run subtasks sequentially or accept expense of new JVMs
                // (i.e., fork()), else will get weird failures when maps try to create/
                // write same dirname or filename:  no chdir() in Java
                while (!Sharpen.Thread.CurrentThread().IsInterrupted())
                {
                    try
                    {
                        @event = this._enclosing.eventQueue.Take();
                    }
                    catch (Exception e)
                    {
                        // mostly via T_KILL? JOB_KILL?
                        LocalContainerLauncher.Log.Error("Returning, interrupted : " + e);
                        break;
                    }
                    LocalContainerLauncher.Log.Info("Processing the event " + @event.ToString());
                    if (@event.GetType() == ContainerLauncher.EventType.ContainerRemoteLaunch)
                    {
                        ContainerRemoteLaunchEvent launchEv = (ContainerRemoteLaunchEvent)@event;
                        // execute the task on a separate thread
                        Future <object> future = this._enclosing.taskRunner.Submit(new _Runnable_228(this,
                                                                                                     launchEv, localMapFiles));
                        // remember the current attempt
                        this.futures[@event.GetTaskAttemptID()] = future;
                    }
                    else
                    {
                        if (@event.GetType() == ContainerLauncher.EventType.ContainerRemoteCleanup)
                        {
                            // cancel (and interrupt) the current running task associated with the
                            // event
                            TaskAttemptId   taId   = @event.GetTaskAttemptID();
                            Future <object> future = Sharpen.Collections.Remove(this.futures, taId);
                            if (future != null)
                            {
                                LocalContainerLauncher.Log.Info("canceling the task attempt " + taId);
                                future.Cancel(true);
                            }
                            // send "cleaned" event to task attempt to move us from
                            // SUCCESS_CONTAINER_CLEANUP to SUCCEEDED state (or
                            // {FAIL|KILL}_CONTAINER_CLEANUP to {FAIL|KILL}_TASK_CLEANUP)
                            this._enclosing.context.GetEventHandler().Handle(new TaskAttemptEvent(taId, TaskAttemptEventType
                                                                                                  .TaContainerCleaned));
                        }
                        else
                        {
                            LocalContainerLauncher.Log.Warn("Ignoring unexpected event " + @event.ToString());
                        }
                    }
                }
            }
 internal virtual void End(BatchingProgressMonitor pm)
 {
     if (output)
     {
         if (totalWork == UNKNOWN)
         {
             pm.OnEndTask(taskName, lastWork);
         }
         else
         {
             int pDone = lastWork * 100 / totalWork;
             pm.OnEndTask(taskName, lastWork, totalWork, pDone);
         }
     }
     if (timerFuture != null)
     {
         timerFuture.Cancel(false);
     }
 }
Exemple #6
0
        /// <exception cref="System.Exception"/>
        /// <exception cref="System.IO.IOException"/>
        private void DoCheckpoint()
        {
            System.Diagnostics.Debug.Assert(canceler != null);
            long txid;

            NNStorage.NameNodeFile imageType;
            // Acquire cpLock to make sure no one is modifying the name system.
            // It does not need the full namesystem write lock, since the only thing
            // that modifies namesystem on standby node is edit log replaying.
            namesystem.CpLockInterruptibly();
            try
            {
                System.Diagnostics.Debug.Assert(namesystem.GetEditLog().IsOpenForRead(), "Standby Checkpointer should only attempt a checkpoint when "
                                                + "NN is in standby mode, but the edit logs are in an unexpected state");
                FSImage img = namesystem.GetFSImage();
                long    prevCheckpointTxId = img.GetStorage().GetMostRecentCheckpointTxId();
                long    thisCheckpointTxId = img.GetLastAppliedOrWrittenTxId();
                System.Diagnostics.Debug.Assert(thisCheckpointTxId >= prevCheckpointTxId);
                if (thisCheckpointTxId == prevCheckpointTxId)
                {
                    Log.Info("A checkpoint was triggered but the Standby Node has not " + "received any transactions since the last checkpoint at txid "
                             + thisCheckpointTxId + ". Skipping...");
                    return;
                }
                if (namesystem.IsRollingUpgrade() && !namesystem.GetFSImage().HasRollbackFSImage(
                        ))
                {
                    // if we will do rolling upgrade but have not created the rollback image
                    // yet, name this checkpoint as fsimage_rollback
                    imageType = NNStorage.NameNodeFile.ImageRollback;
                }
                else
                {
                    imageType = NNStorage.NameNodeFile.Image;
                }
                img.SaveNamespace(namesystem, imageType, canceler);
                txid = img.GetStorage().GetMostRecentCheckpointTxId();
                System.Diagnostics.Debug.Assert(txid == thisCheckpointTxId, "expected to save checkpoint at txid="
                                                + thisCheckpointTxId + " but instead saved at txid=" + txid);
                // Save the legacy OIV image, if the output dir is defined.
                string outputDir = checkpointConf.GetLegacyOivImageDir();
                if (outputDir != null && !outputDir.IsEmpty())
                {
                    img.SaveLegacyOIVImage(namesystem, outputDir, canceler);
                }
            }
            finally
            {
                namesystem.CpUnlock();
            }
            // Upload the saved checkpoint back to the active
            // Do this in a separate thread to avoid blocking transition to active
            // See HDFS-4816
            ExecutorService executor = Executors.NewSingleThreadExecutor(uploadThreadFactory);
            Future <Void>   upload   = executor.Submit(new _Callable_204(this, imageType, txid));

            executor.Shutdown();
            try
            {
                upload.Get();
            }
            catch (Exception e)
            {
                // The background thread may be blocked waiting in the throttler, so
                // interrupt it.
                upload.Cancel(true);
                throw;
            }
            catch (ExecutionException e)
            {
                throw new IOException("Exception during image upload: " + e.Message, e.InnerException
                                      );
            }
        }