-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add appender support #40
Changes from 1 commit
a537bd1
1b20f44
39c09bd
bad705e
2e4e311
a666278
b2fa995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,15 @@ func (s *Storage) create(path string, opt pairStorageCreate) (o *Object) { | |
return o | ||
} | ||
|
||
func (s *Storage) createAppend(ctx context.Context, path string, opt pairStorageCreateAppend) (o *Object, err error) { | ||
o = s.newObject(false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be |
||
o.Mode = ModeRead | ModeAppend | ||
o.ID = s.getAbsPath(path) | ||
o.Path = path | ||
o.SetAppendOffset(0) | ||
return o, nil | ||
} | ||
|
||
func (s *Storage) createMultipart(ctx context.Context, path string, opt pairStorageCreateMultipart) (o *Object, err error) { | ||
input := &service.InitiateMultipartUploadInput{} | ||
if opt.HasEncryptionCustomerAlgorithm { | ||
|
@@ -484,6 +493,31 @@ func (s *Storage) write(ctx context.Context, path string, r io.Reader, size int6 | |
return size, nil | ||
} | ||
|
||
func (s *Storage) writeAppend(ctx context.Context, o *Object, r io.Reader, size int64, opt pairStorageWriteAppend) (n int64, err error) { | ||
rp := o.GetID() | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we don't need to check |
||
offset, ok := o.GetAppendOffset() | ||
if !ok { | ||
err = fmt.Errorf("append offset is not set") | ||
return | ||
} | ||
|
||
output, err := s.bucket.AppendObjectWithContext(ctx, rp, &service.AppendObjectInput{ | ||
Position: &offset, | ||
ContentLength: &size, | ||
Body: io.LimitReader(r, size), | ||
}) | ||
if err != nil { | ||
return | ||
} | ||
|
||
offset = *output.XQSNextAppendPosition | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we need to check it before use. The value could be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether the current data uploaded successfully when the err is nil but the XQSNextAppendPosition is also nil. And what kind of return values are more appropriate in this situation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's won't happen in the normal situation because we know the behavior of So check the value is a safeguard: No matter how the behavior changes, it's won't lead I plan to formalize the errors returned in service, for now, let's just returns a |
||
o.SetAppendOffset(offset) | ||
|
||
return offset, nil | ||
|
||
} | ||
|
||
func (s *Storage) writeMultipart(ctx context.Context, o *Object, r io.Reader, size int64, index int, opt pairStorageWriteMultipart) (n int64, err error) { | ||
if o.Mode&ModePart == 0 { | ||
return 0, fmt.Errorf("object is not a part object") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make them in alphabet order.