@@ -28,66 +28,77 @@ const (
2828
2929// see also: https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
3030const (
31- maxPartsPerUpload = 10000
31+ maxPartsPerUpload = 9999 // 64K limited (compressed) unless (e.g.) `mkfs.xfs -m attr=128k /dev/sdX`
3232)
3333
3434type (
35- uploads struct {
35+ up struct {
36+ u * core.Ufest
37+ rmd map [string ]string
38+ }
39+ ups struct {
3640 t * target
37- m map [string ]* core. Ufest // by upload ID
41+ m map [string ]up
3842 sync.RWMutex
3943 }
4044)
4145
42- func (ups * uploads ) init (id string , lom * core.LOM , metadata map [string ]string ) error {
46+ func (ups * ups ) init (id string , lom * core.LOM , rmd map [string ]string ) error {
4347 manifest := core .NewUfest (id , lom , false /*must-exist*/ )
44- if err := manifest .SetMeta (metadata ); err != nil {
45- return err
46- }
4748 ups .Lock ()
4849 if ups .m == nil {
49- ups .m = make (map [string ]* core. Ufest , iniCapUploads )
50+ ups .m = make (map [string ]up , iniCapUploads )
5051 }
51- ups ._add (id , manifest )
52+ ups ._add (id , manifest , rmd )
5253 ups .Unlock ()
5354 return nil
5455}
5556
56- func (ups * uploads ) _add (id string , manifest * core.Ufest ) {
57+ func (ups * ups ) _add (id string , manifest * core.Ufest , rmd map [ string ] string ) {
5758 debug .Assert (manifest .Lom != nil )
5859 _ , ok := ups .m [id ]
5960 debug .Assert (! ok , "duplicated upload ID: " , id , " " , manifest .Lom .Cname ())
60- ups .m [id ] = manifest
61+ ups .m [id ] = up {manifest , rmd }
62+ }
63+
64+ func (ups * ups ) get (id string ) (manifest * core.Ufest ) {
65+ ups .RLock ()
66+ manifest = ups .m [id ].u
67+ ups .RUnlock ()
68+ return
6169}
6270
63- func (ups * uploads ) get (id string ) (manifest * core.Ufest ) {
71+ func (ups * ups ) getWithMeta (id string ) (manifest * core.Ufest , rmd map [ string ] string ) {
6472 ups .RLock ()
65- manifest = ups .m [id ]
73+ manifest = ups .m [id ].u
74+ rmd = ups .m [id ].rmd
6675 ups .RUnlock ()
6776 return
6877}
6978
7079// NOTE: must be called with ups unlocked
71- func (ups * uploads ) fromFS (id string , lom * core.LOM , add bool ) (manifest * core.Ufest , err error ) {
80+ func (ups * ups ) fromFS (id string , lom * core.LOM , add bool ) (manifest * core.Ufest , err error ) {
7281 manifest = core .NewUfest (id , lom , true /*must-exist*/ )
7382 if err = manifest .Load (lom ); err == nil && add {
7483 ups .Lock ()
75- ups ._add (id , manifest )
84+ ups ._add (id , manifest , nil /*remote metadata <= LOM custom*/ )
7685 ups .Unlock ()
7786 }
7887 return
7988}
8089
81- func (ups * uploads ) abort (id string , lom * core.LOM ) (ecode int , err error ) {
90+ func (ups * ups ) abort (id string , lom * core.LOM ) (ecode int , err error ) {
91+ var manifest * core.Ufest
8292 ups .Lock ()
83- manifest , ok := ups .m [id ]
93+ up , ok := ups .m [id ]
8494 if ! ok {
8595 ups .Unlock ()
8696 manifest , err = ups .fromFS (id , lom , false /*add*/ )
8797 if err != nil {
8898 return 0 , err
8999 }
90100 } else {
101+ manifest = up .u
91102 delete (ups .m , id )
92103 ups .Unlock ()
93104 }
@@ -100,17 +111,17 @@ func (ups *uploads) abort(id string, lom *core.LOM) (ecode int, err error) {
100111 return 0 , nil
101112}
102113
103- func (ups * uploads ) toSlice () (all []* core.Ufest ) {
114+ func (ups * ups ) toSlice () (all []* core.Ufest ) {
104115 ups .RLock ()
105116 all = make ([]* core.Ufest , 0 , len (ups .m ))
106- for _ , manifest := range ups .m {
107- all = append (all , manifest )
117+ for _ , up := range ups .m {
118+ all = append (all , up . u )
108119 }
109120 ups .RUnlock ()
110121 return
111122}
112123
113- func (ups * uploads ) del (id string ) {
124+ func (ups * ups ) del (id string ) {
114125 ups .Lock ()
115126 delete (ups .m , id )
116127 ups .Unlock ()
@@ -120,7 +131,7 @@ func (ups *uploads) del(id string) {
120131// backend operations - encapsulate IsRemoteS3/IsRemoteOCI pattern
121132//
122133
123- func (ups * uploads ) start (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values ) (uploadID string , metadata map [string ]string , err error ) {
134+ func (ups * ups ) start (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values ) (uploadID string , metadata map [string ]string , err error ) {
124135 var (
125136 ecode int
126137 bck = lom .Bck ()
@@ -141,7 +152,7 @@ func (ups *uploads) start(w http.ResponseWriter, r *http.Request, lom *core.LOM,
141152 return
142153}
143154
144- func (ups * uploads ) putPartRemote (lom * core.LOM , reader io.ReadCloser , r * http.Request , q url.Values , uploadID string , expectedSize int64 , partNum int32 ) (etag string , ecode int , err error ) {
155+ func (ups * ups ) putPartRemote (lom * core.LOM , reader io.ReadCloser , r * http.Request , q url.Values , uploadID string , expectedSize int64 , partNum int32 ) (etag string , ecode int , err error ) {
145156 bck := lom .Bck ()
146157 if bck .IsRemoteS3 () {
147158 etag , ecode , err = backend .PutMptPartAWS (lom , reader , r , q , uploadID , expectedSize , partNum )
@@ -152,7 +163,7 @@ func (ups *uploads) putPartRemote(lom *core.LOM, reader io.ReadCloser, r *http.R
152163 return
153164}
154165
155- func (ups * uploads ) completeRemote (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values , uploadID string , body []byte , partList * s3.CompleteMptUpload ) (etag string , err error ) {
166+ func (ups * ups ) completeRemote (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values , uploadID string , body []byte , partList * s3.CompleteMptUpload ) (etag string , err error ) {
156167 var (
157168 ecode int
158169 provider string
@@ -178,7 +189,7 @@ func (ups *uploads) completeRemote(w http.ResponseWriter, r *http.Request, lom *
178189 return
179190}
180191
181- func (ups * uploads ) abortRemote (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values , uploadID string ) (err error ) {
192+ func (ups * ups ) abortRemote (w http.ResponseWriter , r * http.Request , lom * core.LOM , q url.Values , uploadID string ) (err error ) {
182193 var (
183194 ecode int
184195 bck = lom .Bck ()
@@ -194,7 +205,7 @@ func (ups *uploads) abortRemote(w http.ResponseWriter, r *http.Request, lom *cor
194205 return
195206}
196207
197- func (* uploads ) encodeRemoteMetadata (lom * core.LOM , metadata map [string ]string ) (md map [string ]string ) {
208+ func (* ups ) encodeRemoteMetadata (lom * core.LOM , metadata map [string ]string ) (md map [string ]string ) {
198209 bck := lom .Bck ()
199210 if bck .IsRemoteS3 () {
200211 md = cmn .BackendHelpers .Amazon .EncodeMetadata (metadata )
@@ -209,7 +220,7 @@ func (*uploads) encodeRemoteMetadata(lom *core.LOM, metadata map[string]string)
209220// misc
210221//
211222
212- func (* uploads ) parsePartNum (s string ) (int32 , error ) {
223+ func (* ups ) parsePartNum (s string ) (int32 , error ) {
213224 partNum , err := strconv .ParseInt (s , 10 , 32 )
214225 if err != nil {
215226 err = fmt .Errorf ("invalid part number %q (must be in 1-%d range): %v" , s , maxPartsPerUpload , err )
0 commit comments