mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
ensure single threaded access
This commit is contained in:
parent
f24c7e803f
commit
07c2d75ac7
|
@ -8,6 +8,7 @@ import (
|
||||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
"github.com/seaweedfs/seaweedfs/weed/storage/needle"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type VolumeAssignRequest struct {
|
type VolumeAssignRequest struct {
|
||||||
|
@ -66,9 +67,13 @@ func (ap *AssignProxy) Assign(primaryRequest *VolumeAssignRequest, alternativeRe
|
||||||
|
|
||||||
type singleThreadAssignProxy struct {
|
type singleThreadAssignProxy struct {
|
||||||
assignClient master_pb.Seaweed_StreamAssignClient
|
assignClient master_pb.Seaweed_StreamAssignClient
|
||||||
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ap *singleThreadAssignProxy) doAssign(grpcConnection *grpc.ClientConn, primaryRequest *VolumeAssignRequest, alternativeRequests ...*VolumeAssignRequest) (ret *AssignResult, err error) {
|
func (ap *singleThreadAssignProxy) doAssign(grpcConnection *grpc.ClientConn, primaryRequest *VolumeAssignRequest, alternativeRequests ...*VolumeAssignRequest) (ret *AssignResult, err error) {
|
||||||
|
ap.Lock()
|
||||||
|
defer ap.Unlock()
|
||||||
|
|
||||||
if ap.assignClient == nil {
|
if ap.assignClient == nil {
|
||||||
client := master_pb.NewSeaweedClient(grpcConnection)
|
client := master_pb.NewSeaweedClient(grpcConnection)
|
||||||
ap.assignClient, err = client.StreamAssign(context.Background())
|
ap.assignClient, err = client.StreamAssign(context.Background())
|
||||||
|
|
Loading…
Reference in a new issue