/// <summary> /// This method handles the following conditions: /// <ul> /// <li>If retry is not to be processed, return null</li> /// <li>If there is no cache entry, add a new entry /// <paramref name="newEntry"/> /// and return /// it.</li> /// <li>If there is an existing entry, wait for its completion. If the /// completion state is /// <see cref="CacheEntry.Failed"/> /// , the expectation is that the /// thread that waited for completion, retries the request. the /// <see cref="CacheEntry"/> /// state is set to /// <see cref="CacheEntry.Inprogress"/> /// again. /// <li>If the completion state is /// <see cref="CacheEntry.Success"/> /// , the entry is /// returned so that the thread that waits for it can can return previous /// response.</li> /// <ul> /// </summary> /// <returns> /// /// <see cref="CacheEntry"/> /// . /// </returns> private RetryCache.CacheEntry WaitForCompletion(RetryCache.CacheEntry newEntry) { RetryCache.CacheEntry mapEntry = null; Lock.Lock(); try { mapEntry = set.Get(newEntry); // If an entry in the cache does not exist, add a new one if (mapEntry == null) { if (Log.IsTraceEnabled()) { Log.Trace("Adding Rpc request clientId " + newEntry.clientIdMsb + newEntry.clientIdLsb + " callId " + newEntry.callId + " to retryCache"); } set.Put(newEntry); retryCacheMetrics.IncrCacheUpdated(); return(newEntry); } else { retryCacheMetrics.IncrCacheHit(); } } finally { Lock.Unlock(); } // Entry already exists in cache. Wait for completion and return its state Preconditions.CheckNotNull(mapEntry, "Entry from the cache should not be null"); // Wait for in progress request to complete lock (mapEntry) { while (mapEntry.state == RetryCache.CacheEntry.Inprogress) { try { Runtime.Wait(mapEntry); } catch (Exception) { // Restore the interrupted status Thread.CurrentThread().Interrupt(); } } // Previous request has failed, the expectation is is that it will be // retried again. if (mapEntry.state != RetryCache.CacheEntry.Success) { mapEntry.state = RetryCache.CacheEntry.Inprogress; } } return(mapEntry); }
internal static Org.Apache.Hadoop.Hdfs.Server.Namenode.INodeMap NewInstance(INodeDirectory rootDir) { // Compute the map capacity by allocating 1% of total memory int capacity = LightWeightGSet.ComputeCapacity(1, "INodeMap"); GSet <INode, INodeWithAdditionalFields> map = new LightWeightGSet <INode, INodeWithAdditionalFields >(capacity); map.Put(rootDir); return(new Org.Apache.Hadoop.Hdfs.Server.Namenode.INodeMap(map)); }