Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Implement appender support #15

Merged
merged 5 commits into from
Apr 25, 2021
Merged

Implement appender support #15

merged 5 commits into from
Apr 25, 2021

Conversation

JinnyYi
Copy link
Contributor

@JinnyYi JinnyYi commented Apr 23, 2021

Implement appender support in ref: beyondstorage/go-storage#529.

@Xuanwo
Copy link
Collaborator

Xuanwo commented Apr 23, 2021

Please take https://github.com/aos-dev/go-service-fs/blob/master/tests/storage_test.go#L17-L22 a look, run an integration test for oss.

storage.go Outdated
rp := s.getAbsPath(path)

var nextPos int64 = 0
isExist, err := s.bucket.IsObjectExist(rp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to check if this object exists or not, just return error that we got.

storage.go Outdated
}

if isExist {
props, errGetMeta := s.bucket.GetObjectDetailedMeta(rp)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In createAppend, we can use AppendObject with position 0 and size 0 to create an Object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does go-service-oss need to support append to an existing object?

Copy link
Collaborator

@Xuanwo Xuanwo Apr 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but not in this way.

CreateAppend needs to create an append object and should not do other jobs.

In order to append to an existing object, use can:

  • Use Stat to get an append object.
  • Use Create to create an append object if they know the offset.

In both way, the object has ModeAppend, so they can used in WriteAppend to append new content.

storage.go Outdated

func (s *Storage) writeAppend(ctx context.Context, o *Object, r io.Reader, size int64, opt pairStorageWriteAppend) (n int64, err error) {
rp := o.GetID()
nextPos := o.MustGetAppendOffset()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MustGetAppendOffset will panic if append offset does not exist.

In production code, we usually offset, ok := o.GetAppendOffset() and check the returning value to decide whether to return an error or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which error is suitable when the append offset is unset? Do I need to definite error code?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, let's just use fmt.Errorf("append offset is not set"). We will add this error in go-storage.

Makefile Outdated
@@ -32,7 +32,7 @@ test:
go tool cover -html="coverage.txt" -o "coverage.html"

integration_test:
go test -count=1 -race -covermode=atomic -v ./tests
STORAGE_OSS_INTEGRATION_TEST=on go test -count=1 -race -covermode=atomic -v ./tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to set STORAGE_OSS_INTEGRATION_TEST=on here, we will use Makefile.env

storage.go Outdated
options := make([]oss.Option, 0)
options = append(options, oss.ContentLength(0))

offset, err := s.bucket.AppendObject(rp, strings.NewReader(""), 0, options...)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use nil instead of strings.NewReader("") here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the GetReaderLen() in https://github.com/aliyun/aliyun-oss-go-sdk/blob/master/oss/utils.go#L438 will return error if we use nil?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's give it a try. Our integration tests will cover it.

storage.go Outdated
}

o = s.newObject(true)
o = s.newObject(false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create this object with true, as there is no more info we cloud provide.

@Xuanwo
Copy link
Collaborator

Xuanwo commented Apr 23, 2021

Other LGTM, please don't forget to update the docs and examples

@Xuanwo Xuanwo merged commit e7aa31a into master Apr 25, 2021
@Xuanwo Xuanwo deleted the appender-support branch April 25, 2021 03:12
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants