code: func (s *Store) EnsureConfigEntryCAS(idx, cidx uint64, conf structs.ConfigEntry) (bool, error) {
  	tx := s.db.Txn(true)
  	defer tx.Abort()
  
  	// Check for existing configuration.
  	existing, err := tx.First(configTableName, "id", conf.GetKind(), conf.GetName())
  	if err != nil {
  		return false, fmt.Errorf("failed configuration 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.
  	var existingIdx structs.RaftIndex
  	if existing != nil {
  		existingIdx = *existing.(structs.ConfigEntry).GetRaftIndex()
  	}
  	if cidx == 0 && existing != nil {
  		return false, nil
  	}
  	if cidx != 0 && existing == nil {
  		return false, nil
  	}
  	if existing != nil && cidx != 0 && cidx != existingIdx.ModifyIndex {
  		return false, nil
  	}
  
  	if err := s.ensureConfigEntryTxn(tx, idx, conf); err != nil {
  		return false, err
  	}
  
  	tx.Commit()
  	return true, nil
  }
docs: // EnsureConfigEntryCAS is called to do a check-and-set upsert of a given config entry.