func (w *GCWorker) DoGC(safePoint uint64) error {
	gcWorkerCounter.WithLabelValues("do_gc").Inc()

	req := &kvrpcpb.Request{
		Type: kvrpcpb.MessageType_CmdGC,
		CmdGcReq: &kvrpcpb.CmdGCRequest{
			SafePoint: safePoint,
		},
	}
	bo := NewBackoffer(gcMaxBackoff, goctx.Background())

	log.Infof("[gc worker] %s start gc, safePoint: %v.", w.uuid, safePoint)
	startTime := time.Now()
	regions := 0

	var key []byte
	for {
		select {
		case <-w.quit:
			return errors.New("[gc worker] gc job canceled")
		default:
		}

		loc, err := w.store.regionCache.LocateKey(bo, key)
		if err != nil {
			return errors.Trace(err)
		}
		resp, err := w.store.SendKVReq(bo, req, loc.Region, readTimeoutLong)
		if err != nil {
			return errors.Trace(err)
		}
		if regionErr := resp.GetRegionError(); regionErr != nil {
			err = bo.Backoff(boRegionMiss, errors.New(regionErr.String()))
			if err != nil {
				return errors.Trace(err)
			}
			continue
		}
		gcResp := resp.GetCmdGcResp()
		if gcResp == nil {
			return errors.Trace(errBodyMissing)
		}
		if gcResp.GetError() != nil {
			return errors.Errorf("unexpected gc error: %s", gcResp.GetError())
		}
		regions++
		key = loc.EndKey
		if len(key) == 0 {
			break
		}
	}
	log.Infof("[gc worker] %s finish gc, safePoint: %v, regions: %v, cost time: %s", w.uuid, safePoint, regions, time.Since(startTime))
	gcHistogram.WithLabelValues("do_gc").Observe(time.Since(startTime).Seconds())
	return nil
}
// DoGC sends GC command to KV, it is exported for testing purpose.
DoGC sends GC command to KV, it is exported for testing purpose.
// DoGC sends GC command to KV it is exported for testing purpose .
func (w *GCWorker) DoGC(safePoint uint64) error {
	gcWorkerCounter.WithLabelValues("do_gc").Inc()
	req := &kvrpcpb.Request{
		Type: kvrpcpb.MessageType_CmdGC,
		CmdGcReq: &kvrpcpb.CmdGCRequest{
			SafePoint: safePoint,
		},
	}
	bo := NewBackoffer(gcMaxBackoff, goctx.Background())
	log.Infof("[gc worker] %s start gc, safePoint: %v.", w.uuid, safePoint)
	startTime := time.Now()
	regions := 0
	var key []byte
	for {
		select {
		case <-w.quit:
			return errors.New("[gc worker] gc job canceled")
		default:
		}
		loc, err := w.store.regionCache.LocateKey(bo, key)
		if err != nil {
			return errors.Trace(err)
		}
		resp, err := w.store.SendKVReq(bo, req, loc.Region, readTimeoutLong)
		if err != nil {
			return errors.Trace(err)
		}
		if regionErr := resp.GetRegionError(); regionErr != nil {
			err = bo.Backoff(boRegionMiss, errors.New(regionErr.String()))
			if err != nil {
				return errors.Trace(err)
			}
			continue
		}
		gcResp := resp.GetCmdGcResp()
		if gcResp == nil {
			return errors.Trace(errBodyMissing)
		}
		if gcResp.GetError() != nil {
			return errors.Errorf("unexpected gc error: %s", gcResp.GetError())
		}
		regions++
		key = loc.EndKey
		if len(key) == 0 {
			break
		}
	}
	log.Infof("[gc worker] %s finish gc, safePoint: %v, regions: %v, cost time: %s", w.uuid, safePoint, regions, time.Since(startTime))
	gcHistogram.WithLabelValues("do_gc").Observe(time.Since(startTime).Seconds())
	return nil
}
func ( w * GCWorker ) DoGC ( safePoint uint64 ) error { gcWorkerCounter . WithLabelValues ( " " ) . Inc ( ) req := & kvrpcpb . Request { Type : kvrpcpb . MessageType_CmdGC , CmdGcReq : & kvrpcpb . CmdGCRequest { SafePoint : safePoint , } , } bo := NewBackoffer ( gcMaxBackoff , goctx . Background ( ) ) log . Infof ( " " , w . uuid , safePoint ) startTime := time . Now ( ) regions := 0 var key [ ] byte for { select { case <- w . quit : return errors . New ( " " ) default : } loc , err := w . store . regionCache . LocateKey ( bo , key ) if err != nil { return errors . Trace ( err ) } resp , err := w . store . SendKVReq ( bo , req , loc . Region , readTimeoutLong ) if err != nil { return errors . Trace ( err ) } if regionErr := resp . GetRegionError ( ) ; regionErr != nil { err = bo . Backoff ( boRegionMiss , errors . New ( regionErr . String ( ) ) ) if err != nil { return errors . Trace ( err ) } continue } gcResp := resp . GetCmdGcResp ( ) if gcResp == nil { return errors . Trace ( errBodyMissing ) } if gcResp . GetError ( ) != nil { return errors . Errorf ( " " , gcResp . GetError ( ) ) } regions ++ key = loc . EndKey if len ( key ) == 0 { break } } log . Infof ( " " , w . uuid , safePoint , regions , time . Since ( startTime ) ) gcHistogram . WithLabelValues ( " " ) . Observe ( time . Since ( startTime ) . Seconds ( ) ) return nil }
DoGC sends GC command to KV, it is exported for testing purpose.
DoGC sends GC command to KV it is exported for testing purpose .