RetryCache (Apache Hadoop Common 3.5.0 API)
Description: declaration: package: org.apache.hadoop.ipc, class: RetryCache

Package org.apache.hadoop.ipc

# 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.

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `RetryCache.CacheEntry`
  CacheEntry is tracked using unique client ID and callId of the RPC request.
  `static class`
  `RetryCache.CacheEntryWithPayload`
  CacheEntry with payload that tracks the previous response or parts of previous response to be used for generating response for retried requests.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final org.slf4j.Logger`
  `LOG`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `RetryCache(String cacheName, double percentage, long expirationTime)`
  Constructor

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addCacheEntry(byte[] clientId, int callId)`
  Add a new cache entry into the retry cache.
  `void`
  `addCacheEntryWithPayload(byte[] clientId, int callId, Object payload)`
  `static void`
  `clear(RetryCache cache)`
  `String`
  `getCacheName()`
  `LightWeightGSet<RetryCache.CacheEntry,RetryCache.CacheEntry>`
  `getCacheSet()`
  `RetryCacheMetrics`
  `getMetricsForTests()`
  `void`
  `lock()`
  `static void`
  `setState(RetryCache.CacheEntry e, boolean success)`
  `static void`
  `setState(RetryCache.CacheEntryWithPayload e, boolean success, Object payload)`
  `void`
  `unlock()`
  `static RetryCache.CacheEntry`
  `waitForCompletion(RetryCache cache, byte[] clientId, int callId)`
  Static method that provides null check for retryCache.
  `static RetryCache.CacheEntryWithPayload`
  `waitForCompletion(RetryCache cache, Object payload, byte[] clientId, int callId)`
  Static method that provides null check for retryCache.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## 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)