Class RetryCache

java.lang.Object
org.apache.hadoop.ipc.RetryCache

@Private public class RetryCache extends Object
Maintains a cache of non-idempotent requests that have been successfully processed by the RPC server implementation, to handle the retries. A request is uniquely identified by the unique client ID + call ID of the RPC request. On receiving retried request, an entry will be found in the RetryCache and the previous response is sent back to the request.

To look an implementation using this cache, see HDFS FSNamesystem class.

  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
  • Constructor Details

    • RetryCache

      public RetryCache(String cacheName, double percentage, long expirationTime)
      Constructor
      Parameters:
      cacheName - name to identify the cache by
      percentage - percentage of total java heap space used by this cache
      expirationTime - time for an entry to expire in nanoseconds
  • Method Details

    • lock

      public void lock()
    • unlock

      public void unlock()
    • getCacheSet

      @VisibleForTesting public LightWeightGSet<RetryCache.CacheEntry,RetryCache.CacheEntry> getCacheSet()
    • getMetricsForTests

      @VisibleForTesting public RetryCacheMetrics getMetricsForTests()
    • getCacheName

      public String getCacheName()
      Returns:
      This method returns cache name for metrics.
    • addCacheEntry

      public void addCacheEntry(byte[] clientId, int callId)
      Add a new cache entry into the retry cache. The cache entry consists of clientId and callId extracted from editlog.
      Parameters:
      clientId - input clientId.
      callId - input callId.
    • addCacheEntryWithPayload

      public void addCacheEntryWithPayload(byte[] clientId, int callId, Object payload)
    • waitForCompletion

      public static RetryCache.CacheEntry waitForCompletion(RetryCache cache, byte[] clientId, int callId)
      Static method that provides null check for retryCache.
      Parameters:
      cache - input Cache.
      clientId - client id of this request
      callId - client call id of this request
      Returns:
      CacheEntry.
    • waitForCompletion

      public static RetryCache.CacheEntryWithPayload waitForCompletion(RetryCache cache, Object payload, byte[] clientId, int callId)
      Static method that provides null check for retryCache.
      Parameters:
      cache - input cache.
      payload - input payload.
      clientId - client id of this request
      callId - client call id of this request
      Returns:
      CacheEntryWithPayload.
    • setState

      public static void setState(RetryCache.CacheEntry e, boolean success)
    • setState

      public static void setState(RetryCache.CacheEntryWithPayload e, boolean success, Object payload)
    • clear

      public static void clear(RetryCache cache)