Tsz-wo Sze created RATIS-2386:
---------------------------------

             Summary: Improve the data structures in OMFailoverProxyProviderBase
                 Key: RATIS-2386
                 URL: https://issues.apache.org/jira/browse/RATIS-2386
             Project: Ratis
          Issue Type: Improvement
          Components: common
            Reporter: Tsz-wo Sze
            Assignee: Tsz-wo Sze


{code}
//OMFailoverProxyProviderBase
  private Map<String, OMProxyInfo<T>> omProxies;
  private List<String> omNodesInOrder;
{code}
OMFailoverProxyProviderBase currently has
- omProxies: nodeId -> OMProxyInfo (Note that OMProxyInfo has a getNodeId() 
method.)
- omNodesInOrder: int -> nodeId (Note that the ints specify the ordering of the 
proxies)

When getting an OMProxyInfo from an int, it needs to get the nodeId and then 
lookup the omProxies map for OMProxyInfo.  The map lookup is unnecessary.

In this JIRA, we improve the data structures by replacing them with the 
following:
{code}
// Suggested improvement
    /** A list of proxies in a particular order. */
    private final List<OMProxyInfo<P>> proxies;
    /**
     * The ordering of the nodes.
     * <p>
     * Invariant 1: Given a nodeId, let Integer i = ordering.get(nodeId);
     *              If i != null, let info = proxies.get(i), then  
nodeId.equals(info.getNodeId()) == true.
     *              Otherwise, nodeId.equals(info.getNodeId()) == false for any 
info in proxies.
     * <p>
     * Invariant 2: Given a 0 <= i < proxies.size(), let nodeId = 
proxies.get(i).getNodeId().
     *              Then, ordering.get(nodeId) == i.
     */
    private final SortedMap<String, Integer> ordering;
{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to