Skip to content

Commit 328a1da

Browse files
author
root
committed
Pass the upload file size to the http layer if WriteUsesLocalTemp is true
1 parent 4f62e04 commit 328a1da

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

pkg/eosclient/eosgrpc/eos_http/eoshttp.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"io"
2727
"net/http"
2828
"os"
29+
"strconv"
2930
"strings"
3031
"sync"
3132
"time"
@@ -354,10 +355,10 @@ func (c *Client) GETFile(ctx context.Context, remoteuser, uid, gid, urlpath stri
354355
}
355356

356357
// PUTFile does an entire PUT to upload a full file, taking the data from a stream
357-
func (c *Client) PUTFile(ctx context.Context, remoteuser, uid, gid, urlpath string, stream io.ReadCloser) error {
358+
func (c *Client) PUTFile(ctx context.Context, remoteuser, uid, gid, urlpath string, stream io.ReadCloser, length int64) error {
358359

359360
log := appctx.GetLogger(ctx)
360-
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", uid+","+gid).Str("path", urlpath).Msg("")
361+
log.Info().Str("func", "PUTFile").Str("remoteuser", remoteuser).Str("uid,gid", uid+","+gid).Str("path", urlpath).Int64("length", length).Msg("")
361362

362363
// Now send the req and see what happens
363364
finalurl, err := c.buildFullURL(urlpath, uid, gid)
@@ -391,7 +392,7 @@ func (c *Client) PUTFile(ctx context.Context, remoteuser, uid, gid, urlpath stri
391392
log.Debug().Str("func", "PUTFile").Msg("sending req")
392393
resp, err := c.cl.Do(req)
393394

394-
// Let's support redirections... and if we retry we have to retry at the same FST, avoid going back to the MGM
395+
// Let's support redirections... and if we retry we retry at the same FST
395396
if resp != nil && resp.StatusCode == 307 {
396397

397398
// io.Copy(ioutil.Discard, resp.Body)
@@ -407,6 +408,11 @@ func (c *Client) PUTFile(ctx context.Context, remoteuser, uid, gid, urlpath stri
407408
Transport: httpTransport}
408409

409410
req, err = http.NewRequestWithContext(ctx, "PUT", loc.String(), stream)
411+
if length >= 0 {
412+
log.Debug().Str("func", "PUTFile").Int64("Content-Length", length).Msg("setting header")
413+
req.Header.Set("Content-Length", strconv.FormatInt(length, 10))
414+
415+
}
410416
if err != nil {
411417
log.Error().Str("func", "PUTFile").Str("url", loc.String()).Str("err", err.Error()).Msg("can't create redirected request")
412418
return err

pkg/eosclient/eosgrpc/eosgrpc.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ type Options struct {
7474

7575
// Set to true to use the local disk as a buffer for chunk
7676
// writes to EOS. Default is false, i.e. pure streaming
77+
// Beware: in pure streaming mode the FST must support
78+
// the HTTP chunked encoding
7779
WriteUsesLocalTemp bool
7880

7981
// Location of the xrdcopy binary.
@@ -1198,8 +1200,10 @@ func (c *Client) Read(ctx context.Context, uid, gid, path string) (io.ReadCloser
11981200
func (c *Client) Write(ctx context.Context, uid, gid, path string, stream io.ReadCloser) error {
11991201
log := appctx.GetLogger(ctx)
12001202
log.Info().Str("func", "Write").Str("uid,gid", uid+","+gid).Str("path", path).Msg("")
1203+
var length int64
1204+
length = -1
12011205

1202-
if c.opt.ReadUsesLocalTemp {
1206+
if c.opt.WriteUsesLocalTemp {
12031207
fd, err := ioutil.TempFile(c.opt.CacheDirectory, "eoswrite-")
12041208
if err != nil {
12051209
return err
@@ -1209,7 +1213,7 @@ func (c *Client) Write(ctx context.Context, uid, gid, path string, stream io.Rea
12091213

12101214
log.Info().Str("func", "Write").Str("uid,gid", uid+","+gid).Str("path", path).Str("tempfile", fd.Name()).Msg("")
12111215
// copy stream to local temp file
1212-
_, err = io.Copy(fd, stream)
1216+
length, err = io.Copy(fd, stream)
12131217
if err != nil {
12141218
return err
12151219
}
@@ -1221,10 +1225,10 @@ func (c *Client) Write(ctx context.Context, uid, gid, path string, stream io.Rea
12211225
defer wfd.Close()
12221226
defer os.RemoveAll(fd.Name())
12231227

1224-
return c.GetHTTPCl().PUTFile(ctx, "", uid, gid, path, wfd)
1228+
return c.GetHTTPCl().PUTFile(ctx, "", uid, gid, path, wfd, length)
12251229
}
12261230

1227-
return c.GetHTTPCl().PUTFile(ctx, "", uid, gid, path, stream)
1231+
return c.GetHTTPCl().PUTFile(ctx, "", uid, gid, path, stream, length)
12281232

12291233
// return c.GetHttpCl().PUTFile(ctx, remoteuser, uid, gid, urlpathng, stream)
12301234
// return c.WriteFile(ctx, uid, gid, path, fd.Name())

pkg/storage/utils/eosfs/config.go

+2
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,7 @@ type Config struct {
120120
// Normally the eosgrpc plugin streams data on the fly.
121121
// Setting this to true will make reva use the temp cachedirectory
122122
// as intermediate step for write operations
123+
// Beware: in pure streaming mode the FST must support
124+
// the HTTP chunked encoding
123125
WriteUsesLocalTemp bool `mapstructure:"write_uses_local_temp"`
124126
}

0 commit comments

Comments
 (0)