mirror of
				https://github.com/etcd-io/etcd.git
				synced 2024-09-27 06:25:44 +00:00 
			
		
		
		
	Merge pull request #6197 from gyuho/mutex-proxies
integration: fix race in setting shared proxies
This commit is contained in:
		
						commit
						30cf8b7f0f
					
				| @ -17,24 +17,34 @@ | |||||||
| package integration | package integration | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"sync" | ||||||
|  | 
 | ||||||
| 	"github.com/coreos/etcd/clientv3" | 	"github.com/coreos/etcd/clientv3" | ||||||
| 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb" | 	pb "github.com/coreos/etcd/etcdserver/etcdserverpb" | ||||||
| 	"github.com/coreos/etcd/proxy/grpcproxy" | 	"github.com/coreos/etcd/proxy/grpcproxy" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var proxies map[*clientv3.Client]grpcAPI = make(map[*clientv3.Client]grpcAPI) | var ( | ||||||
|  | 	pmu     sync.Mutex | ||||||
|  | 	proxies map[*clientv3.Client]grpcAPI = make(map[*clientv3.Client]grpcAPI) | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| func toGRPC(c *clientv3.Client) grpcAPI { | func toGRPC(c *clientv3.Client) grpcAPI { | ||||||
|  | 	pmu.Lock() | ||||||
|  | 	defer pmu.Unlock() | ||||||
|  | 
 | ||||||
| 	if v, ok := proxies[c]; ok { | 	if v, ok := proxies[c]; ok { | ||||||
| 		return v | 		return v | ||||||
| 	} | 	} | ||||||
| 	return grpcAPI{ | 	api := grpcAPI{ | ||||||
| 		pb.NewClusterClient(c.ActiveConnection()), | 		pb.NewClusterClient(c.ActiveConnection()), | ||||||
| 		grpcproxy.KvServerToKvClient(grpcproxy.NewKvProxy(c)), | 		grpcproxy.KvServerToKvClient(grpcproxy.NewKvProxy(c)), | ||||||
| 		pb.NewLeaseClient(c.ActiveConnection()), | 		pb.NewLeaseClient(c.ActiveConnection()), | ||||||
| 		grpcproxy.WatchServerToWatchClient(grpcproxy.NewWatchProxy(c)), | 		grpcproxy.WatchServerToWatchClient(grpcproxy.NewWatchProxy(c)), | ||||||
| 		pb.NewMaintenanceClient(c.ActiveConnection()), | 		pb.NewMaintenanceClient(c.ActiveConnection()), | ||||||
| 	} | 	} | ||||||
|  | 	proxies[c] = api | ||||||
|  | 	return api | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) { | func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) { | ||||||
| @ -43,7 +53,7 @@ func newClientV3(cfg clientv3.Config) (*clientv3.Client, error) { | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	proxies[c] = toGRPC(c) | 	toGRPC(c) | ||||||
| 	c.KV = clientv3.NewKVFromKVClient(grpcproxy.KvServerToKvClient(grpcproxy.NewKvProxy(c))) | 	c.KV = clientv3.NewKVFromKVClient(grpcproxy.KvServerToKvClient(grpcproxy.NewKvProxy(c))) | ||||||
| 	c.Watcher = clientv3.NewWatchFromWatchClient(grpcproxy.WatchServerToWatchClient(grpcproxy.NewWatchProxy(c))) | 	c.Watcher = clientv3.NewWatchFromWatchClient(grpcproxy.WatchServerToWatchClient(grpcproxy.NewWatchProxy(c))) | ||||||
| 	return c, nil | 	return c, nil | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Gyu-Ho Lee
						Gyu-Ho Lee