code: func (e *Engine) writeSnapshotAndCommit(log *zap.Logger, closedFiles []string, snapshot *Cache) (err error) {
  	defer func() {
  		if err != nil {
  			e.Cache.ClearSnapshot(false)
  		}
  	}()
  
  	// write the new snapshot files
  	newFiles, err := e.Compactor.WriteSnapshot(snapshot)
  	if err != nil {
  		log.Info("Error writing snapshot from compactor", zap.Error(err))
  		return err
  	}
  
  	e.mu.RLock()
  	defer e.mu.RUnlock()
  
  	// update the file store with these new files
  	if err := e.FileStore.Replace(nil, newFiles); err != nil {
  		log.Info("Error adding new TSM files from snapshot", zap.Error(err))
  		return err
  	}
  
  	// clear the snapshot from the in-memory cache, then the old WAL files
  	e.Cache.ClearSnapshot(true)
  
  	if err := e.WAL.Remove(closedFiles); err != nil {
  		log.Info("Error removing closed WAL segments", zap.Error(err))
  	}
  
  	return nil
  }
docs: // writeSnapshotAndCommit will write the passed cache to a new TSM file and remove the closed WAL segments.