dumping uses storage.ExternalFileWriter
to support data export.
storage.ExternalFileWriter
use following APIs:
In order to support multipart uploads, storage.ExternalStorage
will create a struct to carry upload_id and completed parts:
S3Uploader
will create new parts in every call of Write
and complete parts in Close
.
Based on these design, dumping's main data export logic is following:
dumping will create a buffer and call ExternalFileWriter.Write
every time the buffer has been written 1048576(1M) lines.
It's indeed a burden for applications to connect to all storage services, especially for an application that has complicated business logic. So I propose to use aos-dev/go-storage to replace storage.ExternalStorage.
aos-dev/go-storage is an application-oriented unified storage layer for Golang. It's design goals are Production ready, High performance and Vendor agnostic. go-storage will support as many services as possible, including S3, GCS, OSS, COS, Kodo(qiniu), QingStor, even Dropbox(contributed via community).
For the first stage, we can just replace the Write
and Close
call without touching other parts of the projects.
Change the config parse to support construct go-storage's Storager
Way A: Use go-storage's Multiparter to replace storage.ExternalFileWriter
.
Way B: Use go-storage to implement storage.ExternalFileWriter
io.FS
io.FS
has been included in std lib since go 1.16. But io.FS
is designed to work with file instead of bytes or stream. And is's lack of object storage's Multipart Object support.
spf13/afero
afero is another FileSystem Abstraction System for Go. As his name implies, it also works with files.
There is no official support for s3 like services, but there is community built one: afero-s3. It uses S3Manager
to in Write
operations which means user can't control the logic of underlying multipart object.