public boolean processReconfig()

in zookeeper-server/src/main/java/org/apache/zookeeper/server/quorum/QuorumPeer.java [2356:2462]


    public boolean processReconfig(QuorumVerifier qv, Long suggestedLeaderId, Long zxid, boolean restartLE) {
        if (!isReconfigEnabled()) {
            LOG.debug("Reconfig feature is disabled, skip reconfig processing.");
            return false;
        }

        InetSocketAddress oldClientAddr = getClientAddress();
        InetSocketAddress oldSecureClientAddr = getSecureClientAddress();

        // update last committed quorum verifier, write the new config to disk
        // and restart leader election if config changed.
        QuorumVerifier prevQV = setQuorumVerifier(qv, true);

        // There is no log record for the initial config, thus after syncing
        // with leader
        // /zookeeper/config is empty! it is also possible that last committed
        // config is propagated during leader election
        // without the propagation the corresponding log records.
        // so we should explicitly do this (this is not necessary when we're
        // already a Follower/Observer, only
        // for Learner):
        initConfigInZKDatabase();

        recreateSocketAddressesFromQV(prevQV);
        recreateSocketAddressesFromQV(qv);

        if (prevQV.getVersion() < qv.getVersion() && !prevQV.equals(qv)) {
            Map<Long, QuorumServer> newMembers = qv.getAllMembers();
            updateRemotePeerMXBeans(newMembers);
            if (restartLE) {
                restartLeaderElection(prevQV, qv);
            }

            QuorumServer myNewQS = newMembers.get(getMyId());
            if (myNewQS != null) {
                if (myNewQS.clientAddr == null) {
                    if (!isClientAddrFromStatic && oldClientAddr != null && cnxnFactory != null) {
                        // clientAddr omitted in new config, shutdown cnxnFactory
                         cnxnFactory.shutdown();
                         cnxnFactory = null;
                    }
                } else if (!myNewQS.clientAddr.equals(oldClientAddr)) {
                    // clientAddr has changed
                    if (cnxnFactory == null) {
                        // start cnxnFactory first
                        try {
                            cnxnFactory = ServerCnxnFactory.createFactory();
                            cnxnFactory.configure(myNewQS.clientAddr, getMaxClientCnxns(), getClientPortListenBacklog(), false);
                            cnxnFactory.start();
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        cnxnFactory.reconfigure(myNewQS.clientAddr);
                    }
                }

                if (myNewQS.secureClientAddr == null) {
                    if (!isSecureClientAddrFromStatic && oldSecureClientAddr != null && secureCnxnFactory != null) {
                        // secureClientAddr omitted in new config, shutdown secureCnxnFactory
                         secureCnxnFactory.shutdown();
                         secureCnxnFactory = null;
                    }
                } else if (!myNewQS.secureClientAddr.equals(oldSecureClientAddr)) {
                    // secureClientAddr has changed
                    if (secureCnxnFactory == null) {
                        // start secureCnxnFactory first
                        try {
                            configureSSLAuth();
                            secureCnxnFactory = ServerCnxnFactory.createFactory();
                            secureCnxnFactory.configure(myNewQS.secureClientAddr, getMaxClientCnxns(), getClientPortListenBacklog(), true);
                            secureCnxnFactory.start();

                        } catch (IOException | ConfigException e) {
                            throw new RuntimeException(e);
                        }
                    } else {
                        secureCnxnFactory.reconfigure(myNewQS.secureClientAddr);
                    }
                }

                updateThreadName();
            }

            boolean roleChange = updateLearnerType(qv);
            boolean leaderChange = false;
            if (suggestedLeaderId != null) {
                // zxid should be non-null too
                leaderChange = updateVote(suggestedLeaderId, zxid);
            } else {
                long currentLeaderId = getCurrentVote().getId();
                QuorumServer myleaderInCurQV = prevQV.getVotingMembers().get(currentLeaderId);
                QuorumServer myleaderInNewQV = qv.getVotingMembers().get(currentLeaderId);
                leaderChange = (myleaderInCurQV == null
                                || myleaderInCurQV.addr == null
                                || myleaderInNewQV == null
                                || !myleaderInCurQV.addr.equals(myleaderInNewQV.addr));
                // we don't have a designated leader - need to go into leader
                // election
                reconfigFlagClear();
            }

            return roleChange || leaderChange;
        }
        return false;

    }