Fix Race Condition in ReplicatedMergeTree Leader Selection

Fixed the possibility of a race condition when choosing the leader for ReplicatedMergeTree tables.