aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--weed/operation/assign_file_id.go6
-rw-r--r--weed/operation/delete_content.go5
-rw-r--r--weed/operation/lookup.go5
-rw-r--r--weed/operation/stats.go6
-rw-r--r--weed/operation/sync_volume.go6
-rw-r--r--weed/operation/upload_content.go8
-rw-r--r--weed/server/master_server_handlers_admin.go6
-rw-r--r--weed/topology/allocate_volume.go6
-rw-r--r--weed/topology/topology_vacuum.go5
-rw-r--r--weed/util/http_util.go8
10 files changed, 49 insertions, 12 deletions
diff --git a/weed/operation/assign_file_id.go b/weed/operation/assign_file_id.go
index 924b29c0e..00e1caad5 100644
--- a/weed/operation/assign_file_id.go
+++ b/weed/operation/assign_file_id.go
@@ -3,6 +3,7 @@ package operation
import (
"context"
"fmt"
+ "time"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
)
@@ -40,6 +41,9 @@ func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeReque
}
lastError = withMasterServerClient(server, func(masterClient master_pb.SeaweedClient) error {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
req := &master_pb.AssignRequest{
Count: primaryRequest.Count,
Replication: primaryRequest.Replication,
@@ -49,7 +53,7 @@ func Assign(server string, primaryRequest *VolumeAssignRequest, alternativeReque
Rack: primaryRequest.Rack,
DataNode: primaryRequest.DataNode,
}
- resp, grpcErr := masterClient.Assign(context.Background(), req)
+ resp, grpcErr := masterClient.Assign(ctx, req)
if grpcErr != nil {
return grpcErr
}
diff --git a/weed/operation/delete_content.go b/weed/operation/delete_content.go
index e15859d15..3e468e1a3 100644
--- a/weed/operation/delete_content.go
+++ b/weed/operation/delete_content.go
@@ -7,6 +7,7 @@ import (
"net/http"
"strings"
"sync"
+ "time"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
)
@@ -108,12 +109,14 @@ func DeleteFilesWithLookupVolumeId(fileIds []string, lookupFunc func(vid []strin
func DeleteFilesAtOneVolumeServer(volumeServer string, fileIds []string) (ret []*volume_server_pb.DeleteResult, err error) {
err = WithVolumeServerClient(volumeServer, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
req := &volume_server_pb.BatchDeleteRequest{
FileIds: fileIds,
}
- resp, err := volumeServerClient.BatchDelete(context.Background(), req)
+ resp, err := volumeServerClient.BatchDelete(ctx, req)
// fmt.Printf("deleted %v %v: %v\n", fileIds, err, resp)
diff --git a/weed/operation/lookup.go b/weed/operation/lookup.go
index c495af1af..562a11580 100644
--- a/weed/operation/lookup.go
+++ b/weed/operation/lookup.go
@@ -99,10 +99,13 @@ func LookupVolumeIds(server string, vids []string) (map[string]LookupResult, err
//only query unknown_vids
err := withMasterServerClient(server, func(masterClient master_pb.SeaweedClient) error {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
req := &master_pb.LookupVolumeRequest{
VolumeIds: unknown_vids,
}
- resp, grpcErr := masterClient.LookupVolume(context.Background(), req)
+ resp, grpcErr := masterClient.LookupVolume(ctx, req)
if grpcErr != nil {
return grpcErr
}
diff --git a/weed/operation/stats.go b/weed/operation/stats.go
index 277b0e835..364727272 100644
--- a/weed/operation/stats.go
+++ b/weed/operation/stats.go
@@ -2,6 +2,7 @@ package operation
import (
"context"
+ "time"
"github.com/chrislusf/seaweedfs/weed/pb/master_pb"
)
@@ -9,7 +10,10 @@ import (
func Statistics(server string, req *master_pb.StatisticsRequest) (resp *master_pb.StatisticsResponse, err error) {
err = withMasterServerClient(server, func(masterClient master_pb.SeaweedClient) error {
- grpcResponse, grpcErr := masterClient.Statistics(context.Background(), req)
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
+ grpcResponse, grpcErr := masterClient.Statistics(ctx, req)
if grpcErr != nil {
return grpcErr
}
diff --git a/weed/operation/sync_volume.go b/weed/operation/sync_volume.go
index ac2e2bf79..e40c7de41 100644
--- a/weed/operation/sync_volume.go
+++ b/weed/operation/sync_volume.go
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"io"
+ "time"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
. "github.com/chrislusf/seaweedfs/weed/storage/types"
@@ -13,7 +14,10 @@ import (
func GetVolumeSyncStatus(server string, vid uint32) (resp *volume_server_pb.VolumeSyncStatusResponse, err error) {
WithVolumeServerClient(server, func(client volume_server_pb.VolumeServerClient) error {
- resp, err = client.VolumeSyncStatus(context.Background(), &volume_server_pb.VolumeSyncStatusRequest{
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
+ resp, err = client.VolumeSyncStatus(ctx, &volume_server_pb.VolumeSyncStatusRequest{
VolumdId: vid,
})
return nil
diff --git a/weed/operation/upload_content.go b/weed/operation/upload_content.go
index 030bf5889..8cf31e382 100644
--- a/weed/operation/upload_content.go
+++ b/weed/operation/upload_content.go
@@ -13,6 +13,7 @@ import (
"net/textproto"
"path/filepath"
"strings"
+ "time"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/security"
@@ -30,9 +31,10 @@ var (
)
func init() {
- client = &http.Client{Transport: &http.Transport{
- MaxIdleConnsPerHost: 1024,
- }}
+ client = &http.Client{
+ Transport: &http.Transport{MaxIdleConnsPerHost: 1024},
+ Timeout: 5 * time.Second,
+ }
}
var fileNameEscaper = strings.NewReplacer("\\", "\\\\", "\"", "\\\"")
diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.go
index 490693d97..3a2662908 100644
--- a/weed/server/master_server_handlers_admin.go
+++ b/weed/server/master_server_handlers_admin.go
@@ -7,6 +7,7 @@ import (
"math/rand"
"net/http"
"strconv"
+ "time"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/operation"
@@ -24,7 +25,10 @@ func (ms *MasterServer) collectionDeleteHandler(w http.ResponseWriter, r *http.R
}
for _, server := range collection.ListVolumeServers() {
err := operation.WithVolumeServerClient(server.Url(), func(client volume_server_pb.VolumeServerClient) error {
- _, deleteErr := client.DeleteCollection(context.Background(), &volume_server_pb.DeleteCollectionRequest{
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
+ _, deleteErr := client.DeleteCollection(ctx, &volume_server_pb.DeleteCollectionRequest{
Collection: collection.Name,
})
return deleteErr
diff --git a/weed/topology/allocate_volume.go b/weed/topology/allocate_volume.go
index 61fc9d479..55796ab43 100644
--- a/weed/topology/allocate_volume.go
+++ b/weed/topology/allocate_volume.go
@@ -2,6 +2,7 @@ package topology
import (
"context"
+ "time"
"github.com/chrislusf/seaweedfs/weed/operation"
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
@@ -15,7 +16,10 @@ type AllocateVolumeResult struct {
func AllocateVolume(dn *DataNode, vid storage.VolumeId, option *VolumeGrowOption) error {
return operation.WithVolumeServerClient(dn.Url(), func(client volume_server_pb.VolumeServerClient) error {
- _, deleteErr := client.AssignVolume(context.Background(), &volume_server_pb.AssignVolumeRequest{
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
+ _, deleteErr := client.AssignVolume(ctx, &volume_server_pb.AssignVolumeRequest{
VolumdId: uint32(vid),
Collection: option.Collection,
Replication: option.ReplicaPlacement.String(),
diff --git a/weed/topology/topology_vacuum.go b/weed/topology/topology_vacuum.go
index e386dabdb..9b7f295d4 100644
--- a/weed/topology/topology_vacuum.go
+++ b/weed/topology/topology_vacuum.go
@@ -15,7 +15,10 @@ func batchVacuumVolumeCheck(vl *VolumeLayout, vid storage.VolumeId, locationlist
for index, dn := range locationlist.list {
go func(index int, url string, vid storage.VolumeId) {
err := operation.WithVolumeServerClient(url, func(volumeServerClient volume_server_pb.VolumeServerClient) error {
- resp, err := volumeServerClient.VacuumVolumeCheck(context.Background(), &volume_server_pb.VacuumVolumeCheckRequest{
+ ctx, cancel := context.WithTimeout(context.Background(), time.Duration(5*time.Second))
+ defer cancel()
+
+ resp, err := volumeServerClient.VacuumVolumeCheck(ctx, &volume_server_pb.VacuumVolumeCheckRequest{
VolumdId: uint32(vid),
})
if err != nil {
diff --git a/weed/util/http_util.go b/weed/util/http_util.go
index 77a7a5fa3..21e0a678d 100644
--- a/weed/util/http_util.go
+++ b/weed/util/http_util.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"strings"
+ "time"
"github.com/chrislusf/seaweedfs/weed/security"
)
@@ -24,7 +25,10 @@ func init() {
Transport = &http.Transport{
MaxIdleConnsPerHost: 1024,
}
- client = &http.Client{Transport: Transport}
+ client = &http.Client{
+ Transport: Transport,
+ Timeout: 5 * time.Second,
+ }
}
func PostBytes(url string, body []byte) ([]byte, error) {
@@ -63,6 +67,8 @@ func Post(url string, values url.Values) ([]byte, error) {
return b, nil
}
+// github.com/chrislusf/seaweedfs/unmaintained/repeated_vacuum/repeated_vacuum.go
+// may need increasing http.Client.Timeout
func Get(url string) ([]byte, error) {
r, err := client.Get(url)
if err != nil {