code: protected void completeSnapshot(Snapshot snapshot) {
      Assert.notNull(snapshot, "snapshot");
      snapshots.put(snapshot.index(), snapshot);
  
      if (currentSnapshot == null || snapshot.index() > currentSnapshot.index()) {
        currentSnapshot = snapshot;
      }
  
      // Delete old snapshots if necessary.
      if (!storage.retainStaleSnapshots()) {
        Iterator<Map.Entry<Long, Snapshot>> iterator = snapshots.entrySet().iterator();
        while (iterator.hasNext()) {
          Snapshot oldSnapshot = iterator.next().getValue();
          if (oldSnapshot.index() < currentSnapshot.index()) {
            iterator.remove();
            oldSnapshot.close();
            oldSnapshot.delete();
          }
        }
      }
    }
docs: Completes writing a snapshot.