Esempio n. 1
0
        /// <summary>
        /// Acquire the {@code ReadLock} in an <i>unfair</i> way, without waiting for queued up writers.
        /// <p/>
        /// The <seealso cref="ReentrantReadWriteLock.ReadLock.tryLock() tryLock"/>-method of the {@code ReadLock} implementation of
        /// {@code ReentrantReadWriteLock} implements a <i>barging</i> behaviour, where if an exclusive lock is not held,
        /// the shared lock will be acquired, even if there are other threads waiting for the lock. This behaviour is
        /// regardless of whether the lock is fair or not.
        /// <p/>
        /// This allows us to avoid deadlocks where readers would wait for writers that wait for readers in critical
        /// methods.
        /// <p/>
        /// The naive way to implement this method would be:
        /// <pre><code>
        ///     if ( !lock.tryLock() ) // try to barge
        ///         lock.lock(); // fall back to normal blocking lock call
        /// </code></pre>
        /// This would however not implement the appropriate barging behaviour in a scenario like the following: Say the
        /// exclusive lock is held, and there is a queue waiting containing first a reader and then a writer, in this case
        /// the {@code tryLock()} method will return false. If the writer then finishes between the naive implementation
        /// exiting {@code tryLock()} and before entering {@code lock()} the {@code barge(...)} method would now block in
        /// the exact way we don't want it to block, with a read lock held and a writer waiting.<br/>
        /// In order to get around this situation, the implementation of this method uses a
        /// <seealso cref="Lock.tryLock(long, TimeUnit) timed wait"/> in a retry-loop in order to ensure that we make another
        /// attempt to barge the lock at a later point.
        /// <p/>
        /// This method is written to be compatible with the signature of <seealso cref="Lock.lock()"/>, which is not interruptible,
        /// but implemented based on the interruptible <seealso cref="Lock.tryLock(long, TimeUnit)"/>, so the implementation needs to
        /// remember being interrupted, and reset the flag before exiting, so that later invocations of interruptible
        /// methods detect the interruption.
        /// </summary>
        /// <param name="lock"> a <seealso cref="java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock"/> </param>
        private static void Barge(ReentrantReadWriteLock.ReadLock @lock)
        {
            bool interrupted = false;

            // exponential retry back-off, no more than 1 second
            for (long timeout = 10; [email protected](); timeout = Math.Min(1000, timeout * 2))
            {
                try
                {
                    if (@lock.tryLock(timeout, TimeUnit.MILLISECONDS))
                    {
                        return;
                    }
                }
                // the barge()-method is uninterruptable, but implemented based on the interruptible tryLock()-method
                catch (InterruptedException)
                {
                    Thread.interrupted();                            // ensure the interrupt flag is cleared
                    interrupted = true;                              // remember to set interrupt flag before we exit
                }
            }
            if (interrupted)
            {
                Thread.CurrentThread.Interrupt();                         // reset the interrupt flag
            }
        }
        public CommonNodeLabelsManager()
            : base(typeof(CommonNodeLabelsManager).FullName)
        {
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            readLock  = Lock.ReadLock();
            writeLock = Lock.WriteLock();
        }
Esempio n. 3
0
        public QueueCapacities(bool isRoot)
        {
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            readLock      = Lock.ReadLock();
            writeLock     = Lock.WriteLock();
            capacitiesMap = new Dictionary <string, QueueCapacities.Capacities>();
            this.isRoot   = isRoot;
        }
Esempio n. 4
0
            public StatefulContainer(NMClientAsync client, ContainerId containerId)
            {
                this.nmClientAsync = client;
                this.containerId   = containerId;
                stateMachine       = stateMachineFactory.Make(this);
                ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

                readLock  = Lock.ReadLock();
                writeLock = Lock.WriteLock();
            }
Esempio n. 5
0
        public ResourceUsage()
        {
            // short for no-label :)
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            readLock   = Lock.ReadLock();
            writeLock  = Lock.WriteLock();
            usages     = new Dictionary <string, ResourceUsage.UsageByLabel>();
            usages[Nl] = new ResourceUsage.UsageByLabel(Nl);
        }
Esempio n. 6
0
        public RMAppAttemptMetrics(ApplicationAttemptId attemptId, RMContext rmContext)
        {
            // preemption info
            // application headroom
            //HM: Line below replaced by one above for issue wih array 2nd dim
            //new int[NodeType.values().length][NodeType.values().length];
            this.attemptId = attemptId;
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            this.readLock  = Lock.ReadLock();
            this.writeLock = Lock.WriteLock();
            this.rmContext = rmContext;
        }
        /// <summary>Construct the service.</summary>
        /// <param name="name">service name</param>
        public AbstractYarnScheduler(string name)
            : base(name)
        {
            // Nodes in the cluster, indexed by NodeId
            // Whole capacity of the cluster

            /*
             * All schedulers which are inheriting AbstractYarnScheduler should use
             * concurrent version of 'applications' map.
             */
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            this.maxAllocReadLock  = Lock.ReadLock();
            this.maxAllocWriteLock = Lock.WriteLock();
        }
Esempio n. 8
0
        public ApplicationImpl(Dispatcher dispatcher, string user, ApplicationId appId, Credentials
                               credentials, Context context)
        {
            this.dispatcher  = dispatcher;
            this.user        = user;
            this.appId       = appId;
            this.credentials = credentials;
            this.aclsManager = context.GetApplicationACLsManager();
            this.context     = context;
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            readLock     = Lock.ReadLock();
            writeLock    = Lock.WriteLock();
            stateMachine = stateMachineFactory.Make(this);
        }
Esempio n. 9
0
        public RMContainerImpl(Container container, ApplicationAttemptId appAttemptId, NodeId
                               nodeId, string user, RMContext rmContext, long creationTime)
        {
            // Transitions from NEW state
            // Transitions from RESERVED state
            // nothing to do
            // nothing to do
            // Transitions from ALLOCATED state
            // Transitions from ACQUIRED state
            // Transitions from RUNNING state
            // Transitions from COMPLETED state
            // Transitions from EXPIRED state
            // Transitions from RELEASED state
            // Transitions from KILLED state
            // create the topology tables
            this.stateMachine = stateMachineFactory.Make(this);
            this.containerId  = container.GetId();
            this.nodeId       = nodeId;
            this.container    = container;
            this.appAttemptId = appAttemptId;
            this.user         = user;
            this.creationTime = creationTime;
            this.rmContext    = rmContext;
            this.eventHandler = rmContext.GetDispatcher().GetEventHandler();
            this.containerAllocationExpirer = rmContext.GetContainerAllocationExpirer();
            this.isAMContainer    = false;
            this.resourceRequests = null;
            ReentrantReadWriteLock Lock = new ReentrantReadWriteLock();

            this.readLock              = Lock.ReadLock();
            this.writeLock             = Lock.WriteLock();
            saveNonAMContainerMetaInfo = rmContext.GetYarnConfiguration().GetBoolean(YarnConfiguration
                                                                                     .ApplicationHistorySaveNonAmContainerMetaInfo, YarnConfiguration.DefaultApplicationHistorySaveNonAmContainerMetaInfo
                                                                                     );
            rmContext.GetRMApplicationHistoryWriter().ContainerStarted(this);
            // If saveNonAMContainerMetaInfo is true, store system metrics for all
            // containers. If false, and if this container is marked as the AM, metrics
            // will still be published for this container, but that calculation happens
            // later.
            if (saveNonAMContainerMetaInfo)
            {
                rmContext.GetSystemMetricsPublisher().ContainerCreated(this, this.creationTime);
            }
        }