private void eliminateDuplicates(List<MessageInfo> messageEntries) {
    Set<StoreKey> setToFindDuplicate = new HashSet<>();
    // first remove the ttl update MessageInfo of any key whose put MessageInfo is already present
    messageEntries.removeIf(
        messageInfo -> !messageInfo.isDeleted() && !messageInfo.isUndeleted() && !setToFindDuplicate.add(
            messageInfo.getStoreKey()));
    // next, remove any put/ttl update if a delete is present
    setToFindDuplicate.clear();
    ListIterator<MessageInfo> messageEntriesIterator = messageEntries.listIterator(messageEntries.size());
    while (messageEntriesIterator.hasPrevious()) {
      MessageInfo messageInfo = messageEntriesIterator.previous();
      if (!setToFindDuplicate.add(messageInfo.getStoreKey())) {
        messageEntriesIterator.remove();
      }
    }
  }
We can have duplicate entries in the message entries since updates can happen to the same key. For example,
insert a key followed by a delete. This would create two entries in the journal or the index. A single findInfo
could read both the entries. The findInfo should return as clean information as possible.
<p/>
This function choose a delete entry over all entries but chooses a put entry over a ttl update entry
@param messageEntries The message entry list where duplicates need to be removed
ambry-store/src/main/java/com/github/ambry/store/PersistentIndex.java