aboutsummaryrefslogtreecommitdiff
path: root/weed/server/volume_grpc_copy.go
diff options
context:
space:
mode:
author石昌林 <changlin.shi@ly.com>2022-06-20 21:12:44 +0800
committer石昌林 <changlin.shi@ly.com>2022-06-20 21:12:44 +0800
commit81f7f08708a169e2a6a9478b86c40684ea4422b3 (patch)
tree5c6222d3d3cb6529d153996d4337b493209cf60b /weed/server/volume_grpc_copy.go
parent9e2d6e897ed457b354e42e82787b3f86b70cc669 (diff)
downloadseaweedfs-81f7f08708a169e2a6a9478b86c40684ea4422b3.tar.xz
seaweedfs-81f7f08708a169e2a6a9478b86c40684ea4422b3.zip
Determine whether to preallocate according to the master configuration before executing copy volume
Diffstat (limited to 'weed/server/volume_grpc_copy.go')
-rw-r--r--weed/server/volume_grpc_copy.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/weed/server/volume_grpc_copy.go b/weed/server/volume_grpc_copy.go
index e3ec5b724..b4bc850e2 100644
--- a/weed/server/volume_grpc_copy.go
+++ b/weed/server/volume_grpc_copy.go
@@ -3,6 +3,8 @@ package weed_server
import (
"context"
"fmt"
+ "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
+ "github.com/chrislusf/seaweedfs/weed/storage/backend"
"io"
"math"
"os"
@@ -78,6 +80,28 @@ func (vs *VolumeServer) VolumeCopy(req *volume_server_pb.VolumeCopyRequest, stre
}
}()
+ var preallocateSize int64
+ if grpcErr := pb.WithMasterClient(false, vs.GetMaster(), vs.grpcDialOption, func(client master_pb.SeaweedClient) error {
+ resp, err := client.GetMasterConfiguration(context.Background(), &master_pb.GetMasterConfigurationRequest{})
+ if err != nil {
+ return fmt.Errorf("get master %s configuration: %v", vs.GetMaster(), err)
+ }
+ if resp.VolumePreallocate {
+ preallocateSize = int64(resp.VolumeSizeLimitMB) * (1 << 20)
+ }
+ return nil
+ }); grpcErr != nil {
+ glog.V(0).Infof("connect to %s: %v", vs.GetMaster(), grpcErr)
+ }
+
+ if preallocateSize > 0 {
+ volumeFile := dataBaseFileName + ".dat"
+ _, err := backend.CreateVolumeFile(volumeFile, preallocateSize, 0)
+ if err != nil {
+ return fmt.Errorf("create volume file %s: %v", volumeFile, err)
+ }
+ }
+
// println("source:", volFileInfoResp.String())
copyResponse := &volume_server_pb.VolumeCopyResponse{}
reportInterval := int64(1024 * 1024 * 128)