code: func (s *Store) Snapshot() (raft.FSMSnapshot, error) {
  	s.restoreMu.RLock()
  	defer s.restoreMu.RUnlock()
  
  	// Snapshots are not permitted while any connection has a transaction
  	// in progress, because it's not possible (not without a lot of extra
  	// code anyway) to capture the state of a connection during a transaction
  	// on that connection. Since only during Apply() can a connection change
  	// its transaction state, and Apply() is never called concurrently with
  	// this call, it's safe to check transaction state here across all connections.
  	if err := func() error {
  		s.connsMu.Lock()
  		defer s.connsMu.Unlock()
  		for _, c := range s.conns {
  			if c.TransactionActive() {
  				stats.Add(numSnaphotsBlocked, 1)
  				return ErrTransactionActive
  			}
  		}
  		return nil
  	}(); err != nil {
  		return nil, err
  	}
  
  	// Copy the database.
  	fsm := &fsmSnapshot{}
  	var buf bytes.Buffer
  	var err error
  	err = s.database(false, &buf)
  	if err != nil {
  		s.logger.Printf("failed to read database for snapshot: %s", err.Error())
  		return nil, err
  	}
  	fsm.database = buf.Bytes()
  
  	// Copy the node metadata.
  	fsm.meta, err = json.Marshal(s.meta)
  	if err != nil {
  		s.logger.Printf("failed to encode meta for snapshot: %s", err.Error())
  		return nil, err
  	}
  
  	// Copy the active connections.
  	fsm.connections, err = json.Marshal(s.conns)
  	if err != nil {
  		s.logger.Printf("failed to encode connections for snapshot: %s", err.Error())
  		return nil, err
  	}
  	stats.Add(numSnaphots, 1)
  
  	return fsm, nil
  }
docs: // Snapshot returns a snapshot of the store. The caller must ensure that
  // no Raft transaction is taking place during this call. Hashicorp Raft
  // guarantees that this function will not be called concurrently with Apply.