public Snapshot getOrCreateSnapshot(long epoch) {
        Snapshot last = head.prev();
        if (last.epoch() > epoch) {
            throw new RuntimeException("Can't create a new in-memory snapshot at epoch " + epoch +
                " because there is already a snapshot with epoch " + last.epoch() + ". Snapshot epochs are " +
                epochsToString());
        } else if (last.epoch() == epoch) {
            return last;
        }
        Snapshot snapshot = new Snapshot(epoch);
        last.appendNext(snapshot);
        snapshots.put(epoch, snapshot);
        log.debug("Creating in-memory snapshot {}", epoch);
        return snapshot;
    }
Creates a new snapshot at the given epoch.
<br>
If {@code epoch} already exists and it is the last snapshot then just return that snapshot.

@param epoch             The epoch to create the snapshot at.  The current epoch
                         will be advanced to one past this epoch.
server-common/src/main/java/org/apache/kafka/timeline/SnapshotRegistry.java