def check_invariants(self) -> None:
        """Checks invariant of ``synchronous_standby_names`` and ``/sync`` key in DCS.

        .. seealso::
            Check :class:`QuorumStateResolver`'s docstring for more information.

        :raises:
            :exc:`QuorumError`: in case of broken state"""
        voters = CaseInsensitiveSet(self.voters | CaseInsensitiveSet([self.leader]))
        sync = CaseInsensitiveSet(self.sync | CaseInsensitiveSet([self.leader_wanted]))

        # We need to verify that subset of nodes that can acknowledge a commit overlaps
        # with any subset of nodes that can achieve quorum to promote a new leader.
        # ``+ 1`` is required because the leader is included in the set.
        if self.voters and not (len(voters | sync) <= self.quorum + self.numsync + 1):
            len_nodes = len(voters | sync)
            raise QuorumError("Quorum and sync not guaranteed to overlap: "
                              f"nodes {len_nodes} >= quorum {self.quorum} + sync {self.sync} + 1")
        # unstable cases, we are changing synchronous_standby_names and /sync key
        # one after another, hence one set is allowed to be a subset of another
        if not (voters.issubset(sync) or sync.issubset(voters)):
            voters_only = voters - sync
            sync_only = sync - voters
            raise QuorumError(f"Mismatched sets: voter only={voters_only} sync only={sync_only}")
Checks invariant of ``synchronous_standby_names`` and ``/sync`` key in DCS.

        .. seealso::
            Check :class:`QuorumStateResolver`'s docstring for more information.

        :raises:
            :exc:`QuorumError`: in case of broken state
patroni/quorum.py