code: func (s *Store) ensureServiceCASTxn(tx *memdb.Txn, idx uint64, node string, svc *structs.NodeService) (bool, error) {
  	// Retrieve the existing service.
  	existing, err := tx.First("services", "id", node, svc.ID)
  	if err != nil {
  		return false, fmt.Errorf("failed service 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 svc.ModifyIndex == 0 && existing != nil {
  		return false, nil
  	}
  	if svc.ModifyIndex != 0 && existing == nil {
  		return false, nil
  	}
  	e, ok := existing.(*structs.Node)
  	if ok && svc.ModifyIndex != 0 && svc.ModifyIndex != e.ModifyIndex {
  		return false, nil
  	}
  
  	// Perform the update.
  	if err := s.ensureServiceTxn(tx, idx, node, svc); err != nil {
  		return false, err
  	}
  
  	return true, nil
  }
docs: // ensureServiceCASTxn updates a service only if the existing index matches the given index.
  // Returns a bool indicating if a write happened and any error.