public Optional<Node> getLeaderNode(int leaderMainNodeId, ClientIdMetadata clientId, String listenerName) {
        BrokerRegistration target = metadataCache.getNode(leaderMainNodeId);
        if (target == null) {
            return Optional.empty();
        }
        String clientRack = clientId.rack();
        if (clientRack == null) {
            // If the client rack isn't set, then return the main node.
            return target.node(listenerName);
        }

        Map<Integer, BrokerRegistration> clientRackMain2proxy = main2proxyByRack.get(clientRack);
        if (clientRackMain2proxy == null) {
            // If the cluster doesn't cover the client rack, the producer should directly send records to the main node.
            return target.node(listenerName);
        }

        // Get the proxy node.
        BrokerRegistration proxy = clientRackMain2proxy.get(target.id());
        if (proxy == null) {
            // The producer rack is the same as the leader rack.
            return target.node(listenerName);
        }
        return proxy.node(listenerName);
    }
Get the proxy leader node when NOT_LEADER_OR_FOLLOWER happens.
core/src/main/java/kafka/automq/zerozone/ProxyNodeMapping.java