func (d Driver) Open(path string) (kv.Storage, error) {
	mc.mu.Lock()
	defer mc.mu.Unlock()

	u, err := url.Parse(path)
	if err != nil {
		return nil, errors.Trace(err)
	}

	engineSchema := filepath.Join(u.Host, u.Path)
	if store, ok := mc.cache[engineSchema]; ok {
		// TODO: check the cache store has the same engine with this Driver.
		log.Info("[kv] cache store", engineSchema)
		return store, nil
	}

	db, err := d.Driver.Open(engineSchema)
	if err != nil {
		return nil, errors.Trace(err)
	}

	log.Info("[kv] New store", engineSchema)
	s := &dbStore{
		txns:       make(map[uint64]*dbTxn),
		keysLocked: make(map[string]uint64),
		uuid:       uuid.NewV4().String(),
		path:       engineSchema,
		db:         db,
		compactor:  newLocalCompactor(localCompactDefaultPolicy, db),
		closed:     false,
	}
	s.recentUpdates, err = segmentmap.NewSegmentMap(100)
	if err != nil {
		return nil, errors.Trace(err)
	}
	regionServers := buildLocalRegionServers(s)
	var infos []*regionInfo
	for _, rs := range regionServers {
		ri := &regionInfo{startKey: rs.startKey, endKey: rs.endKey, rs: rs}
		infos = append(infos, ri)
	}
	s.pd.SetRegionInfo(infos)
	mc.cache[engineSchema] = s
	s.compactor.Start()
	return s, nil
}
// Open opens or creates a storage with specific format for a local engine Driver.
// The path should be a URL format which is described in tidb package.
Open opens or creates a storage with specific format for a local engine Driver.
The path should be a URL format which is described in tidb package.
// Open opens or creates a storage with specific format for a local engine Driver . // The path should be a URL format which is described in tidb package .
func (d Driver) Open(path string) (kv.Storage, error) {
	mc.mu.Lock()
	defer mc.mu.Unlock()
	u, err := url.Parse(path)
	if err != nil {
		return nil, errors.Trace(err)
	}
	engineSchema := filepath.Join(u.Host, u.Path)
	if store, ok := mc.cache[engineSchema]; ok {
		log.Info("[kv] cache store", engineSchema)
		return store, nil
	}
	db, err := d.Driver.Open(engineSchema)
	if err != nil {
		return nil, errors.Trace(err)
	}
	log.Info("[kv] New store", engineSchema)
	s := &dbStore{
		txns:       make(map[uint64]*dbTxn),
		keysLocked: make(map[string]uint64),
		uuid:       uuid.NewV4().String(),
		path:       engineSchema,
		db:         db,
		compactor:  newLocalCompactor(localCompactDefaultPolicy, db),
		closed:     false,
	}
	s.recentUpdates, err = segmentmap.NewSegmentMap(100)
	if err != nil {
		return nil, errors.Trace(err)
	}
	regionServers := buildLocalRegionServers(s)
	var infos []*regionInfo
	for _, rs := range regionServers {
		ri := &regionInfo{startKey: rs.startKey, endKey: rs.endKey, rs: rs}
		infos = append(infos, ri)
	}
	s.pd.SetRegionInfo(infos)
	mc.cache[engineSchema] = s
	s.compactor.Start()
	return s, nil
}
func ( d Driver ) Open ( path string ) ( kv . Storage , error ) { mc . mu . Lock ( ) defer mc . mu . Unlock ( ) u , err := url . Parse ( path ) if err != nil { return nil , errors . Trace ( err ) } engineSchema := filepath . Join ( u . Host , u . Path ) if store , ok := mc . cache [ engineSchema ] ; ok { log . Info ( " " , engineSchema ) return store , nil } db , err := d . Driver . Open ( engineSchema ) if err != nil { return nil , errors . Trace ( err ) } log . Info ( " " , engineSchema ) s := & dbStore { txns : make ( map [ uint64 ] * dbTxn ) , keysLocked : make ( map [ string ] uint64 ) , uuid : uuid . NewV4 ( ) . String ( ) , path : engineSchema , db : db , compactor : newLocalCompactor ( localCompactDefaultPolicy , db ) , closed : false , } s . recentUpdates , err = segmentmap . NewSegmentMap ( 100 ) if err != nil { return nil , errors . Trace ( err ) } regionServers := buildLocalRegionServers ( s ) var infos [ ] * regionInfo for _ , rs := range regionServers { ri := & regionInfo { startKey : rs . startKey , endKey : rs . endKey , rs : rs } infos = append ( infos , ri ) } s . pd . SetRegionInfo ( infos ) mc . cache [ engineSchema ] = s s . compactor . Start ( ) return s , nil }
Open opens or creates a storage with specific format for a local engine Driver.
Open opens or creates a storage with specific format for a local engine Driver .
// TODO: check the cache store has the same engine with this Driver.