Пример #1
0
 public static void SetState(RetryCache.CacheEntry e, bool success)
 {
     if (e == null)
     {
         return;
     }
     e.Completed(success);
 }
Пример #2
0
 /// <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);
 }
Пример #3
0
 public override bool Equals(object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     if (!(obj is RetryCache.CacheEntry))
     {
         return(false);
     }
     RetryCache.CacheEntry other = (RetryCache.CacheEntry)obj;
     return(callId == other.callId && clientIdMsb == other.clientIdMsb && clientIdLsb
            == other.clientIdLsb);
 }
Пример #4
0
 /// <summary>Add a new cache entry into the retry cache.</summary>
 /// <remarks>
 /// Add a new cache entry into the retry cache. The cache entry consists of
 /// clientId and callId extracted from editlog.
 /// </remarks>
 public virtual void AddCacheEntry(byte[] clientId, int callId)
 {
     RetryCache.CacheEntry newEntry = new RetryCache.CacheEntry(clientId, callId, Runtime
                                                                .NanoTime() + expirationTime, true);
     Lock.Lock();
     try
     {
         set.Put(newEntry);
     }
     finally
     {
         Lock.Unlock();
     }
     retryCacheMetrics.IncrCacheUpdated();
 }