-
Notifications
You must be signed in to change notification settings - Fork 102
storage: S3 test refactoring and fix some bugs #548
Conversation
this requires s3_test to be placed into a separate storage_test package to avoid circular dependency. this makes the `checkS3` hack not usable. instead, we introduced a new option struct to the constructor to disable to the check.
The
Previously it was just However, according to the interface comment of
So @glorv do you have the actual error which leads to the Read loop in the first place, so we could add it to the test case? |
I can confirm that this fixes our issue. |
LGTM |
The root cause is that some code in |
LGTM |
cherry pick to release-4.0 failed |
This reverts commit 9066e09.
* storage: replace s3Handlers by the standard s3iface.S3API interface * storage: publish RangeInfo for testing * storage: use gomock instead of mockS3Handlers for proper mocking this requires s3_test to be placed into a separate storage_test package to avoid circular dependency. this makes the `checkS3` hack not usable. instead, we introduced a new option struct to the constructor to disable to the check. * storage/s3: fix FileExists always `return true, nil` on non-AWS error * storage/s3: do not use ReadFull to implement Read * storage/s3: fix incorrect usage of NextMarker in WalkDir
What problem does this PR solve?
What is changed and how it works?
Upgrade fake-gcs-server from 1.17.0 to 1.19.0 to include Support Windows fsouza/fake-gcs-server#228 (note: the latest version is 1.21.1 but that upgrades the gRPC dependency to 1.31.1 which maybe too new for other dependencies such as etcd and the TiDB cluster. we choose 1.19.0 to avoid upgrading the deps too much).
Removed the
storage.s3Handlers
type, becauses3iface.S3API
exists. We also removed themockS3Handler
type ins3_test.go
in favor of a real mocking framework.Naively using step 2 caused a dependency cycle between
pkg/mock
andpkg/storage
. Therefore we moveds3_test.go
into its own packagestorage_test
, which leads to some privacy problems. We have performed the following changes:RangeInfo
is now public.TestS3Others
test, relying ondefineS3Flags
but performs no tests, is removed.checkS3
hack is removed, in favor of options passed to the ExternalStorage constructor (see below).Responding to the change in step 3, we generalized the
storage.Create
function to accept anExternalStorageOptions
struct replacing thesendCreds
boolean. The options are:sendCreds
booleancheckS3
hack, and generalized to Local and GCSnewGCSStorage
andnewGCSStorageWithHTTPClient
functions, and generalized to S3.While running the tests, the following bugs are also fixed in this PR:
S3Storage.FileExists
was returningtrue, nil
if the HeadObject requests returned any non-AWS errors. This is now changed to returnfalse, err
.s3StorageReader.Read
returns0, nil
when reaching EOF, because we usedio.ReadFull
rather than(io.Reader).Read
(dunno why). This causesio.ErrNoProgress
when wrapping abufio.Reader
on the reader, which affects Lightning's S3 data source. Changed to the latter so it properly return0, io.EOF
.WalkDir
previously is implemented using theListObjects
API, using theNextMarker
field as continuation token. Unfortunately, this field is missing on AWS S3 when Delimiter is empty (it is always populated on minio and Aliyun OSS), so when there are over 1000 objects,WalkDir
will enter an infinite loop! Here we change the Marker calculation by using the last Key in the Contents instead, as recommended in the docs.Check List
Tests
Code changes
storage.Create
is soft-deprecated andstorage.NewS3Storage
is hard-deprecated. They can still be used but are discouraged. In particular TiCDC should stop usingstorage.NewS3Storage
, it makes no sense to not usestorage.ParseBackend
+storage.New
.Side effects
Related changes
Release Note