SERVER-46667 and other bugs are the result of comparing member indexes from different replica set configs, or using a member index from one config as an array index in a different config.
Devise a way to avoid repeating these sorts of bugs. Two ideas:
1. Minimize all use of member indexes from configs, ReplSetMetadata, OplogQueryMetadata, etc. Try to find alternative means of accomplishing the same goals.
2. Anywhere that member indexes are compared, include the config version and term. Perhaps create a MemberIndex class that has an index, version, and term. Two MemberIndexes cannot be compared unless their versions and terms agree. The name MemberIndex may be too similar to MemberId, so let's ponder the name.
3. Hide member indexes behind safe interfaces. E.g., instead of using OplogQueryMetadata.getSyncSourceIndex() directly, create safer methods like hasSyncSourceIndex() or isSameSyncSourceIndex(MemberIndex i).