Skip to content

Conversation

@szetszwo
Copy link
Contributor

What changes were proposed in this pull request?

//OMFailoverProxyProviderBase
  private Map<String, OMProxyInfo<T>> omProxies;
  private List<String> omNodesInOrder;

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:
    /** 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, then nodeId.equals(info.getNodeId()) == true, where info = proxies.get(i).
     *              Otherwise, i == null, then nodeId.equals(info.getNodeId()) == false for any info in proxies.
     * <p>
     * Invariant 2: Given 0 <= i < proxies.size(), let nodeId = proxies.get(i).getNodeId().
     *              Then, ordering.get(nodeId) == i.
     */
    private final SortedMap<String, Integer> ordering;
  • We also move them to a new class with unmodifiable collections. As a result, no synchronization is needed in the new class.

What is the link to the Apache JIRA

HDDS-14470

How was this patch tested?

By updating existing tests.

Copy link
Contributor

@ivandika3 ivandika3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@szetszwo Thanks for the improvement. Overall LGTM.

* Invariant 2: Given 0 <= i < proxies.size(), let nodeId = proxies.get(i).getNodeId().
* Then, ordering.get(nodeId) == i.
*/
private final SortedMap<String, Integer> ordering;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a SortedMap since it's simply storing the nodeId -> index mapping and the ordering is already configured in proxies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally use SortedMap for printing the ids in alphabetical order. It actually is a bug since it should use the original ordering for getNodeIds(). Will fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants