Skip to content

Commit

Permalink
Remove unnecessary locks on DiscoveryNodeManager
Browse files Browse the repository at this point in the history
Threads which try to 'getAllNode' or 'getActiveConnectorNodes'
could be against with thread that are refreshing workers state.
This control of race condition seems unnecessary, so removing locks
may be improve performance slightly.
  • Loading branch information
XuPengfei-1020 committed Jan 2, 2024
1 parent 33dd20a commit 4235626
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,11 @@ public final class DiscoveryNodeManager
private final InternalNode currentNode;
private final boolean allCatalogsOnAllNodes;

@GuardedBy("this")
private Optional<SetMultimap<CatalogHandle, InternalNode>> activeNodesByCatalogHandle = Optional.empty();

@GuardedBy("this")
private AllNodes allNodes;
private volatile AllNodes allNodes;

@GuardedBy("this")
private Set<InternalNode> coordinators;
private volatile Set<InternalNode> coordinators;

@GuardedBy("this")
private final List<Consumer<AllNodes>> listeners = new ArrayList<>();
Expand Down Expand Up @@ -305,7 +302,7 @@ private boolean isNodeShuttingDown(String nodeId)
}

@Override
public synchronized AllNodes getAllNodes()
public AllNodes getAllNodes()
{
return allNodes;
}
Expand Down Expand Up @@ -343,7 +340,7 @@ public Set<InternalNode> getNodes(NodeState state)
}

@Override
public synchronized Set<InternalNode> getActiveCatalogNodes(CatalogHandle catalogHandle)
public Set<InternalNode> getActiveCatalogNodes(CatalogHandle catalogHandle)
{
// activeNodesByCatalogName is immutable
return activeNodesByCatalogHandle
Expand All @@ -352,7 +349,7 @@ public synchronized Set<InternalNode> getActiveCatalogNodes(CatalogHandle catalo
}

@Override
public synchronized NodesSnapshot getActiveNodesSnapshot()
public NodesSnapshot getActiveNodesSnapshot()
{
return new NodesSnapshot(allNodes.getActiveNodes(), activeNodesByCatalogHandle);
}
Expand All @@ -364,7 +361,7 @@ public InternalNode getCurrentNode()
}

@Override
public synchronized Set<InternalNode> getCoordinators()
public Set<InternalNode> getCoordinators()
{
return coordinators;
}
Expand Down

0 comments on commit 4235626

Please sign in to comment.