func (do *Domain) Reload() error {
	// for test
	if do.SchemaValidity.MockReloadFailed.getValue() {
		return do.mockReloadFailed()
	}

	// Lock here for only once at the same time.
	do.m.Lock()
	defer do.m.Unlock()

	var err error
	var latestSchemaVersion int64
	for i := 0; i < loadRetryTimes; i++ {
		startTime := time.Now()
		var ver kv.Version
		ver, err = do.store.CurrentVersion()
		if err == nil {
			schemaVersion := int64(0)
			oldInfoSchema := do.infoHandle.Get()
			if oldInfoSchema != nil {
				schemaVersion = oldInfoSchema.SchemaMetaVersion()
			}
			latestSchemaVersion, err = do.loadInfoSchema(do.infoHandle, schemaVersion, ver.Ver)
		}
		if err == nil {
			atomic.StoreInt64(&do.lastLeaseTS, time.Now().UnixNano())
			do.SchemaValidity.updateTimeInfo(startTime.UnixNano(), ver.Ver)
			do.SchemaValidity.updateSchemaVersion(latestSchemaVersion)
			sub := time.Since(startTime)
			lease := do.DDL().GetLease()
			if sub > lease && lease > 0 {
				log.Infof("[ddl] loading schema takes a long time %v", sub)
			}
			break
		}
		log.Errorf("[ddl] load schema err %v, ver:%v, retry again", errors.ErrorStack(err), ver.Ver)
		// TODO: Use a backoff algorithm.
		time.Sleep(doReloadSleepTime)
	}

	return errors.Trace(err)
}
// Reload reloads InfoSchema.
// It's public in order to do the test.
Reload reloads InfoSchema.
It's public in order to do the test.
// Reload reloads InfoSchema . // It ' s public in order to do the test .
func (do *Domain) Reload() error {
	if do.SchemaValidity.MockReloadFailed.getValue() {
		return do.mockReloadFailed()
	}
	do.m.Lock()
	defer do.m.Unlock()
	var err error
	var latestSchemaVersion int64
	for i := 0; i < loadRetryTimes; i++ {
		startTime := time.Now()
		var ver kv.Version
		ver, err = do.store.CurrentVersion()
		if err == nil {
			schemaVersion := int64(0)
			oldInfoSchema := do.infoHandle.Get()
			if oldInfoSchema != nil {
				schemaVersion = oldInfoSchema.SchemaMetaVersion()
			}
			latestSchemaVersion, err = do.loadInfoSchema(do.infoHandle, schemaVersion, ver.Ver)
		}
		if err == nil {
			atomic.StoreInt64(&do.lastLeaseTS, time.Now().UnixNano())
			do.SchemaValidity.updateTimeInfo(startTime.UnixNano(), ver.Ver)
			do.SchemaValidity.updateSchemaVersion(latestSchemaVersion)
			sub := time.Since(startTime)
			lease := do.DDL().GetLease()
			if sub > lease && lease > 0 {
				log.Infof("[ddl] loading schema takes a long time %v", sub)
			}
			break
		}
		log.Errorf("[ddl] load schema err %v, ver:%v, retry again", errors.ErrorStack(err), ver.Ver)
		time.Sleep(doReloadSleepTime)
	}
	return errors.Trace(err)
}
func ( do * Domain ) Reload ( ) error { if do . SchemaValidity . MockReloadFailed . getValue ( ) { return do . mockReloadFailed ( ) } do . m . Lock ( ) defer do . m . Unlock ( ) var err error var latestSchemaVersion int64 for i := 0 ; i < loadRetryTimes ; i ++ { startTime := time . Now ( ) var ver kv . Version ver , err = do . store . CurrentVersion ( ) if err == nil { schemaVersion := int64 ( 0 ) oldInfoSchema := do . infoHandle . Get ( ) if oldInfoSchema != nil { schemaVersion = oldInfoSchema . SchemaMetaVersion ( ) } latestSchemaVersion , err = do . loadInfoSchema ( do . infoHandle , schemaVersion , ver . Ver ) } if err == nil { atomic . StoreInt64 ( & do . lastLeaseTS , time . Now ( ) . UnixNano ( ) ) do . SchemaValidity . updateTimeInfo ( startTime . UnixNano ( ) , ver . Ver ) do . SchemaValidity . updateSchemaVersion ( latestSchemaVersion ) sub := time . Since ( startTime ) lease := do . DDL ( ) . GetLease ( ) if sub > lease && lease > 0 { log . Infof ( " " , sub ) } break } log . Errorf ( " " , errors . ErrorStack ( err ) , ver . Ver ) time . Sleep ( doReloadSleepTime ) } return errors . Trace ( err ) }
Reload reloads InfoSchema.
Reload reloads InfoSchema .
// for test // Lock here for only once at the same time. // TODO: Use a backoff algorithm.