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.s3Handlerstype, becauses3iface.S3APIexists. We also removed themockS3Handlertype ins3_test.goin favor of a real mocking framework.Naively using step 2 caused a dependency cycle between
pkg/mockandpkg/storage. Therefore we moveds3_test.gointo its own packagestorage_test, which leads to some privacy problems. We have performed the following changes:RangeInfois now public.TestS3Otherstest, relying ondefineS3Flagsbut performs no tests, is removed.checkS3hack is removed, in favor of options passed to the ExternalStorage constructor (see below).Responding to the change in step 3, we generalized the
storage.Createfunction to accept anExternalStorageOptionsstruct replacing thesendCredsboolean. The options are:sendCredsbooleancheckS3hack, and generalized to Local and GCSnewGCSStorageandnewGCSStorageWithHTTPClientfunctions, and generalized to S3.While running the tests, the following bugs are also fixed in this PR:
S3Storage.FileExistswas returningtrue, nilif the HeadObject requests returned any non-AWS errors. This is now changed to returnfalse, err.s3StorageReader.Readreturns0, nilwhen reaching EOF, because we usedio.ReadFullrather than(io.Reader).Read(dunno why). This causesio.ErrNoProgresswhen wrapping abufio.Readeron the reader, which affects Lightning's S3 data source. Changed to the latter so it properly return0, io.EOF.WalkDirpreviously is implemented using theListObjectsAPI, using theNextMarkerfield 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,WalkDirwill 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.Createis soft-deprecated andstorage.NewS3Storageis 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