func()

in datasource/etcd/sync.go [55:105]


func (s *SyncManager) SyncAll(ctx context.Context) error {
	enable := config.GetBool("sync.enableOnStart", false)
	if !enable {
		return nil
	}
	ctx = putil.SetContext(ctx, putil.CtxEnableSync, "1")
	exist, err := etcdadpt.Exist(ctx, SyncAllKey)
	if err != nil {
		return err
	}
	if exist {
		log.Info(fmt.Sprintf("%s key already exists, do not need to do tasks", SyncAllKey))
		return datasource.ErrSyncAllKeyExists
	}
	lock, err := etcdadpt.TryLock(SyncAllLockKey, defaultLockTime)
	if err != nil || lock == nil {
		log.Info(fmt.Sprintf("%s lock not acquired", SyncAllLockKey))
		return nil
	}
	defer func(lock *etcdadpt.DLock) {
		err := lock.Unlock()
		if err != nil {
			log.Error(fmt.Sprintf("fail to unlock the %s key", SyncAllLockKey), err)
		}
	}(lock)
	err = syncAllRoles(ctx)
	if err != nil {
		return err
	}
	err = syncAllAccounts(ctx)
	if err != nil {
		return err
	}
	err = syncAllServices(ctx)
	if err != nil {
		return err
	}
	err = syncAllTags(ctx)
	if err != nil {
		return err
	}
	err = syncAllSchemas(ctx)
	if err != nil {
		return err
	}
	err = syncAllDependencies(ctx)
	if err != nil {
		return err
	}
	return etcdadpt.Put(ctx, SyncAllKey, "1")
}