code: func (s *Store) kvsSetCASTxn(tx *memdb.Txn, idx uint64, entry *structs.DirEntry) (bool, error) {
  	// Retrieve the existing entry.
  	existing, err := tx.First("kvs", "id", entry.Key)
  	if err != nil {
  		return false, fmt.Errorf("failed kvs lookup: %s", err)
  	}
  
  	// Check if the we should do the set. A ModifyIndex of 0 means that
  	// we are doing a set-if-not-exists.
  	if entry.ModifyIndex == 0 && existing != nil {
  		return false, nil
  	}
  	if entry.ModifyIndex != 0 && existing == nil {
  		return false, nil
  	}
  	e, ok := existing.(*structs.DirEntry)
  	if ok && entry.ModifyIndex != 0 && entry.ModifyIndex != e.ModifyIndex {
  		return false, nil
  	}
  
  	// If we made it this far, we should perform the set.
  	if err := s.kvsSetTxn(tx, idx, entry, false); err != nil {
  		return false, err
  	}
  	return true, nil
  }
docs: // kvsSetCASTxn is the inner method used to do a CAS inside an existing
  // transaction.