code: func (a *Allocator) allocateServices(ctx context.Context, existingAddressesOnly bool) error {
  	var (
  		nc       = a.netCtx
  		services []*api.Service
  		err      error
  	)
  	a.store.View(func(tx store.ReadTx) {
  		services, err = store.FindServices(tx, store.All)
  	})
  	if err != nil {
  		return errors.Wrap(err, "error listing all services in store while trying to allocate during init")
  	}
  
  	var allocatedServices []*api.Service
  	for _, s := range services {
  		if nc.nwkAllocator.IsServiceAllocated(s, networkallocator.OnInit) {
  			continue
  		}
  		if existingAddressesOnly &&
  			(s.Endpoint == nil ||
  				len(s.Endpoint.VirtualIPs) == 0) {
  			continue
  		}
  
  		if err := a.allocateService(ctx, s, existingAddressesOnly); err != nil {
  			log.G(ctx).WithField("existingAddressesOnly", existingAddressesOnly).WithError(err).Errorf("failed allocating service %s during init", s.ID)
  			continue
  		}
  		allocatedServices = append(allocatedServices, s)
  	}
  
  	if err := a.store.Batch(func(batch *store.Batch) error {
  		for _, s := range allocatedServices {
  			if err := a.commitAllocatedService(ctx, batch, s); err != nil {
  				log.G(ctx).WithError(err).Errorf("failed committing allocation of service %s during init", s.ID)
  			}
  		}
  		return nil
  	}); err != nil {
  		for _, s := range allocatedServices {
  			log.G(ctx).WithError(err).Errorf("failed committing allocation of service %v during init", s.GetID())
  		}
  	}
  
  	return nil
  }
docs: // allocateServices allocates services in the store so far before we process
  // watched events.