Ejemplo n.º 1
0
 public virtual void IncrementFileCountForLocalCacheDirectory(Path cacheDir)
 {
     if (useLocalCacheDirectoryManager)
     {
         Path cacheRoot = LocalCacheDirectoryManager.GetCacheDirectoryRoot(cacheDir);
         if (cacheRoot != null)
         {
             LocalCacheDirectoryManager dir = directoryManagers[cacheRoot];
             if (dir == null)
             {
                 dir = new LocalCacheDirectoryManager(conf);
                 LocalCacheDirectoryManager otherDir = directoryManagers.PutIfAbsent(cacheRoot, dir
                                                                                     );
                 if (otherDir != null)
                 {
                     dir = otherDir;
                 }
             }
             if (cacheDir.Equals(cacheRoot))
             {
                 dir.IncrementFileCountForPath(string.Empty);
             }
             else
             {
                 string dirStr  = cacheDir.ToUri().GetRawPath();
                 string rootStr = cacheRoot.ToUri().GetRawPath();
                 dir.IncrementFileCountForPath(Sharpen.Runtime.Substring(dirStr, rootStr.Length +
                                                                         1));
             }
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>Add a new metrics to the registry</summary>
 /// <param name="metricsName">- the name</param>
 /// <param name="theMetricsObj">- the metrics</param>
 /// <exception cref="System.ArgumentException">if a name is already registered</exception>
 public virtual void Add(string metricsName, MetricsBase theMetricsObj)
 {
     if (metricsList.PutIfAbsent(metricsName, theMetricsObj) != null)
     {
         throw new ArgumentException("Duplicate metricsName:" + metricsName);
     }
 }
Ejemplo n.º 3
0
 internal static TestBlockScanner.TestScanResultHandler.Info GetInfo(FsVolumeSpi volume
                                                                     )
 {
     TestBlockScanner.TestScanResultHandler.Info newInfo = new TestBlockScanner.TestScanResultHandler.Info
                                                               ();
     TestBlockScanner.TestScanResultHandler.Info prevInfo = infos.PutIfAbsent(volume.GetStorageID
                                                                                  (), newInfo);
     return(prevInfo == null ? newInfo : prevInfo);
 }
Ejemplo n.º 4
0
        // Root and Intermediate
        /// <summary>
        /// Returns a
        /// <see cref="SchedulingPolicy"/>
        /// instance corresponding to the passed clazz
        /// </summary>
        public static SchedulingPolicy GetInstance(Type clazz)
        {
            SchedulingPolicy policy    = ReflectionUtils.NewInstance(clazz, null);
            SchedulingPolicy policyRet = instances.PutIfAbsent(clazz, policy);

            if (policyRet != null)
            {
                return(policyRet);
            }
            return(policy);
        }
Ejemplo n.º 5
0
 private MetricsInfo[] GetGcInfo(string gcName)
 {
     MetricsInfo[] gcInfo = gcInfoCache[gcName];
     if (gcInfo == null)
     {
         gcInfo    = new MetricsInfo[2];
         gcInfo[0] = Interns.Info("GcCount" + gcName, "GC Count for " + gcName);
         gcInfo[1] = Interns.Info("GcTimeMillis" + gcName, "GC Time for " + gcName);
         MetricsInfo[] previousGcInfo = gcInfoCache.PutIfAbsent(gcName, gcInfo);
         if (previousGcInfo != null)
         {
             return(previousGcInfo);
         }
     }
     return(gcInfo);
 }
Ejemplo n.º 6
0
        private T Get <T>() where T : TranslationBundle
        {
            System.Type       type   = typeof(T);
            TranslationBundle bundle = map.Get(type);

            if (bundle == null)
            {
                bundle = GlobalBundleCache.LookupBundle <T>(locale);
                // There is a small opportunity for a race, which we may
                // lose. Accept defeat and return the winner's instance.
                TranslationBundle old = map.PutIfAbsent(type, bundle);
                if (old != null)
                {
                    bundle = old;
                }
            }
            return((T)bundle);
        }
Ejemplo n.º 7
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual FileSystem CreateFileSystem(Configuration namenodeConf
                                                               )
        {
            string user = UserGroupInformation.GetCurrentUser().GetShortUserName();

            FileSystemAccessService.CachedFileSystem newCachedFS = new FileSystemAccessService.CachedFileSystem
                                                                       (purgeTimeout);
            FileSystemAccessService.CachedFileSystem cachedFS = fsCache.PutIfAbsent(user, newCachedFS
                                                                                    );
            if (cachedFS == null)
            {
                cachedFS = newCachedFS;
            }
            Configuration conf = new Configuration(namenodeConf);

            conf.Set(HttpfsFsUser, user);
            return(cachedFS.GetFileSytem(conf));
        }
Ejemplo n.º 8
0
        private ContainerLauncherImpl.Container GetContainer(ContainerLauncherEvent @event
                                                             )
        {
            ContainerId id = @event.GetContainerID();

            ContainerLauncherImpl.Container c = containers[id];
            if (c == null)
            {
                c = new ContainerLauncherImpl.Container(this, @event.GetTaskAttemptID(), @event.GetContainerID
                                                            (), @event.GetContainerMgrAddress());
                ContainerLauncherImpl.Container old = containers.PutIfAbsent(id, c);
                if (old != null)
                {
                    c = old;
                }
            }
            return(c);
        }
Ejemplo n.º 9
0
        // cache the canonicalized hostnames;  the cache currently isn't expired,
        // but the canonicals will only change if the host's resolver configuration
        // changes
        private static string CanonicalizeHost(string host)
        {
            // check if the host has already been canonicalized
            string fqHost = canonicalizedHostCache[host];

            if (fqHost == null)
            {
                try
                {
                    fqHost = SecurityUtil.GetByName(host).GetHostName();
                    // slight race condition, but won't hurt
                    canonicalizedHostCache.PutIfAbsent(host, fqHost);
                }
                catch (UnknownHostException)
                {
                    fqHost = host;
                }
            }
            return(fqHost);
        }
Ejemplo n.º 10
0
 /// <summary>Add group to cache</summary>
 /// <param name="group">name of the group to add to cache</param>
 /// <param name="users">list of users for a given group</param>
 public static void Add(string group, IList <string> users)
 {
     foreach (string user in users)
     {
         ICollection <string> userGroups = userToNetgroupsMap[user];
         // ConcurrentHashMap does not allow null values;
         // So null value check can be used to check if the key exists
         if (userGroups == null)
         {
             //Generate a ConcurrentHashSet (backed by the keyset of the ConcurrentHashMap)
             userGroups = Collections.NewSetFromMap(new ConcurrentHashMap <string, bool
                                                                           >());
             ICollection <string> currentSet = userToNetgroupsMap.PutIfAbsent(user, userGroups);
             if (currentSet != null)
             {
                 userGroups = currentSet;
             }
         }
         userGroups.AddItem(group);
     }
 }
Ejemplo n.º 11
0
Archivo: XMap.cs Proyecto: slagusev/api
 /// <summary>
 /// Try to add a value to the map.
 /// </summary>
 internal T Add(string key, T value)
 {
     while (true)
     {
         var newEntry = new SoftReference <T>(value);
         var entry    = map.PutIfAbsent(key, newEntry);
         if (entry != null)
         {
             // There was an entry in the map.
             var result = entry.Get();
             if (result != null)
             {
                 // The entry holds a valid reference, we're done
                 return(result);
             }
             else
             {
                 // The entry has been cleared
                 map.Replace(key, newEntry);
             }
         }
     }
 }
Ejemplo n.º 12
0
        /// <summary>Get the number of occurrences and increment atomically.</summary>
        /// <param name="identity">the identity of the user to increment</param>
        /// <returns>the value before incrementation</returns>
        /// <exception cref="System.Exception"/>
        private long GetAndIncrement(object identity)
        {
            // We will increment the count, or create it if no such count exists
            AtomicLong count = this.callCounts[identity];

            if (count == null)
            {
                // Create the count since no such count exists.
                count = new AtomicLong(0);
                // Put it in, or get the AtomicInteger that was put in by another thread
                AtomicLong otherCount = callCounts.PutIfAbsent(identity, count);
                if (otherCount != null)
                {
                    count = otherCount;
                }
            }
            // Update the total
            totalCalls.GetAndIncrement();
            // At this point value is guaranteed to be not null. It may however have
            // been clobbered from callCounts. Nonetheless, we return what
            // we have.
            return(count.GetAndIncrement());
        }
        public override void UpdateAttempt(TaskAttemptStatusUpdateEvent.TaskAttemptStatus
                                           status, long timestamp)
        {
            base.UpdateAttempt(status, timestamp);
            TaskAttemptId attemptID = status.id;
            TaskId        taskID    = attemptID.GetTaskId();
            JobId         jobID     = taskID.GetJobId();

            Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job job = context.GetJob(jobID);
            if (job == null)
            {
                return;
            }
            Task task = job.GetTask(taskID);

            if (task == null)
            {
                return;
            }
            TaskAttempt taskAttempt = task.GetAttempt(attemptID);

            if (taskAttempt == null)
            {
                return;
            }
            long boxedStart = startTimes[attemptID];
            long start      = boxedStart == null ? long.MinValue : boxedStart;

            // We need to do two things.
            //  1: If this is a completion, we accumulate statistics in the superclass
            //  2: If this is not a completion, we learn more about it.
            // This is not a completion, but we're cooking.
            //
            if (taskAttempt.GetState() == TaskAttemptState.Running)
            {
                // See if this task is already in the registry
                AtomicLong estimateContainer         = attemptRuntimeEstimates[taskAttempt];
                AtomicLong estimateVarianceContainer = attemptRuntimeEstimateVariances[taskAttempt
                                                       ];
                if (estimateContainer == null)
                {
                    if (attemptRuntimeEstimates[taskAttempt] == null)
                    {
                        attemptRuntimeEstimates[taskAttempt] = new AtomicLong();
                        estimateContainer = attemptRuntimeEstimates[taskAttempt];
                    }
                }
                if (estimateVarianceContainer == null)
                {
                    attemptRuntimeEstimateVariances.PutIfAbsent(taskAttempt, new AtomicLong());
                    estimateVarianceContainer = attemptRuntimeEstimateVariances[taskAttempt];
                }
                long estimate         = -1;
                long varianceEstimate = -1;
                // This code assumes that we'll never consider starting a third
                //  speculative task attempt if two are already running for this task
                if (start > 0 && timestamp > start)
                {
                    estimate         = (long)((timestamp - start) / Math.Max(0.0001, status.progress));
                    varianceEstimate = (long)(estimate * status.progress / 10);
                }
                if (estimateContainer != null)
                {
                    estimateContainer.Set(estimate);
                }
                if (estimateVarianceContainer != null)
                {
                    estimateVarianceContainer.Set(varianceEstimate);
                }
            }
        }
Ejemplo n.º 14
0
 public void TestPutIfAbsent2_NullReferenceException()
 {
     try
     {
         ConcurrentHashMap<Object, Object> c = new ConcurrentHashMap<Object, Object>(5);
         c.PutIfAbsent("whatever", null);
         ShouldThrow();
     }
     catch(NullReferenceException)
     {
     }
 }